|
|
back to boardWhy do i get WA? #include <stdio.h> #define max(a, b) ((a) > (b) ? (a) : (b)) int main(void) { long int v = 0; long int k = 0; int finish = 0;
while(!finish) { int ch = fgetc(stdin); if(ch != EOF) { if('0' <= ch && ch <= '9') ch = ch - 48; else if('A' <= ch && ch <= 'Z') ch = ch - 55; else ch = -1;
if(ch != -1) { v = v + ch; if(ch > k) k = ch; } else finish = 1;
} else finish = 1; }
if(k == 0) { printf("No solution.\n"); return 0; }
for(; k < 36; k ++) if(v % k == 0) { printf("%ld\n", k + 1); return 0; }
printf("No solution.\n"); return 0; } This is my program. If you can find me an example that my program won't run corectly please let me know. Thanks. Now you'll get AC :) (+) Just a little change that you don't take in account. Luck! #include <stdio.h> #define max(a, b) ((a) > (b) ? (a) : (b)) int main(void) { long int v = 0; long int k = 1; int finish = 0; while(!finish) { int ch = fgetc(stdin); if(ch != EOF) { if('0' <= ch && ch <= '9') ch = ch - 48; else if('A' <= ch && ch <= 'Z') ch = ch - 55; else ch = -1; if(ch != -1) { v = v + ch; if(ch > k) k = ch; } else finish = 1; } else finish = 1; } for(; k < 36; k ++) if(v % k == 0) { printf("%ld\n", k + 1); return 0; } printf("No solution.\n"); return 0; } Re: Now you'll get AC :) (+) Thanks. I've got AC. But why should k be 1? Your program failed with a n = 0, it returns "no solution"(-) > #include <stdio.h> > > #define max(a, b) ((a) > (b) ? (a) : (b)) > > int main(void) > { > long int v = 0; > long int k = 0; > int finish = 0; > > while(!finish) > { > int ch = fgetc(stdin); > if(ch != EOF) > { > if('0' <= ch && ch <= '9') ch = ch - 48; > else if('A' <= ch && ch <= 'Z') ch = ch - 55; > else ch = -1; > > if(ch != -1) > { > v = v + ch; > if(ch > k) k = ch; > } else finish = 1; > > } else finish = 1; > } > > if(k == 0) > { > printf("No solution.\n"); > return 0; > } > > for(; k < 36; k ++) > if(v % k == 0) > { > printf("%ld\n", k + 1); > return 0; > } > > printf("No solution.\n"); > return 0; > } > > This is my program. If you can find me an example that my program > won't run corectly please let me know. Thanks. |
|
|