|
|
back to boardthat's seem easy but why I got WA #include <stdio.h> #include <ctype.h> int main() { long num=0,k,v,max=1; char ch; ch=getchar(); while(ch!=EOF) { if(isdigit(ch)) v=ch-'0'; else v=ch-'A'+10; num+=v; if(v>max) max=v; ch=getchar(); } for(k=max;k<36;k++) if(num%k==0) break; if(k<36) printf("%ld",k+1); else printf("No solution."); return 0; } There may be other characters (e.g. spaces , returns) too. Good luck! > #include <stdio.h> > #include <ctype.h> > int main() > { > long num=0,k,v,max=1; > char ch; > ch=getchar(); > while(ch!=EOF) > { > if(isdigit(ch)) v=ch-'0'; > else v=ch-'A'+10; > num+=v; > if(v>max) max=v; > ch=getchar(); > } > for(k=max;k<36;k++) > if(num%k==0) break; > if(k<36) printf("%ld",k+1); > else printf("No solution."); > return 0; > } that make me got WA over 10 times .thank you very P'Sam I've got accept > > #include <stdio.h> > > #include <ctype.h> > > int main() > > { > > long num=0,k,v,max=1; > > char ch; > > ch=getchar(); > > while(ch!=EOF) > > { > > if(isdigit(ch)) v=ch-'0'; > > else v=ch-'A'+10; > > num+=v; > > if(v>max) max=v; > > ch=getchar(); > > } > > for(k=max;k<36;k++) > > if(num%k==0) break; > > if(k<36) printf("%ld",k+1); > > else printf("No solution."); > > return 0; > > } Here is your mistake NOT EOF BUT '\n' #include <stdio.h> #include <ctype.h> long num=0,v,max=1,k; char ch; int main() { ch=getchar(); do { if(isdigit(ch)) v=ch-48; else v=ch-55; num+=v; if(v>max) max=v; ch=getchar(); } while(ch!='\n'); if(max==0) printf("2"); else { for(k=max;k<36;k++) if(num%k==0) break; if(k<36) printf("%ld",k+1); else printf("No solution."); } return 0; } |
|
|