ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1104. Don’t Ask Woman about Her Age

Why i don't get AC ?
Posted by PersonalJesus 16 Oct 2007 23:47
Can somebody help me with my solution - i don't know where is my mistake? As you can see i always get WA on test 8.


#include<iostream>
#include<string>
using namespace std;
string s;
char c='0';
int base,st;

int f(int b)
{
 long long sol=0;
 for(int i=0;i<s.size();i++)
  if(s[i]>='0' && s[i]<='9') sol=(sol*b+int(s[i]-'0'))%(b-1);
   else if(s[i]>='A' && s[i]<='Z') sol=(sol*b+int(c-'A')+10)%(b-1);
 if(sol==0) return 1;
  else return 0;
}

int main()
{
 while(c!='\n') {scanf("%c",&c); if((c>='0' && c<='9' ) || (c>='A' && c<='Z'))s+=c;}
 c='0';
 for(int i=0;i<s.size();i++)
  {
   if(int(c)<int(s[i])) c=s[i];
  }
 if(c>='0' && c<='9') st=int(c-'0');
  else if(c>='A' && c<='Z') st=int(c-'A')+10;
 if(st==0) {printf("2\n"); return 0;}
 for(int i=st+1;i<=36;i++)
  if(f(i)==1)
   {
    printf("%d\n",i);
    return 0;
   }
 printf("No solution.\n");
 return 0;
}