|
|
вернуться в форумwhy i have 2 WA already ? Plz help me, i not understand why i have WA. #include <stdio.h> int main() { int i,j=0,tmp,real; int K; int wantnum=0; int grp[101]; scanf("%d",&K); for(i=0; i<K; i++) { scanf("%d",&tmp); if((tmp%2 == 0)) continue; grp[j] = tmp; j++; } real=j; for(i=0; i<K; i++) for(j=0; j<K-i; j++) if(grp[j] > grp[j+1]) { tmp=grp[j]; grp[j]=grp[j+1]; grp[j+1]=tmp; } for(i=0; i<real/2+1; i++) wantnum += grp[i]/2+1; printf("%d",wantnum); return 0; } Re: why i have 2 WA already ? your bubble sort is not working right. add -1 on the second for check for(i=0; i<K; i++) for(j=0; j<K-i - 1; j++) if(grp[j] > grp[j+1]) { tmp=grp[j]; grp[j]=grp[j+1]; grp[j+1]=tmp; } sorry for my english :P Plz help me, i not understand why i have WA. #include <stdio.h> int main() { int i,j=0,tmp,real; int K; int wantnum=0; int grp[101]; scanf("%d",&K); for(i=0; i<K; i++) { scanf("%d",&tmp); if((tmp%2 == 0)) continue; grp[j] = tmp; j++; } real=j; for(i=0; i<K; i++) for(j=0; j<K-i; j++) if(grp[j] > grp[j+1]) { tmp=grp[j]; grp[j]=grp[j+1]; grp[j+1]=tmp; } for(i=0; i<real/2+1; i++) wantnum += grp[i]/2+1; printf("%d",wantnum); return 0; } Plz help me, i not understand why i have WA. #include <stdio.h> int main() { int i,j=0,tmp,real; int K; int wantnum=0; int grp[101]; scanf("%d",&K); for(i=0; i<K; i++) { scanf("%d",&tmp); if((tmp%2 == 0)) continue; grp[j] = tmp; j++; } real=j; for(i=0; i<K; i++) for(j=0; j<K-i; j++) if(grp[j] > grp[j+1]) { tmp=grp[j]; grp[j]=grp[j+1]; grp[j+1]=tmp; } for(i=0; i<real/2+1; i++) wantnum += grp[i]/2+1; printf("%d",wantnum); return 0; } |
|
|