This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

10093

By: a guest on Mar 25th, 2012  |  syntax: C++  |  size: 0.85 KB  |  views: 48  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*
  2.  uva - 10093
  3.  written by shaheen
  4. */
  5. #include<iostream>
  6. #include<cstring>
  7. #include<cstdio>
  8. #include<cctype>
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13.   string s;
  14.   while(cin >> s)
  15.   {
  16.     int base = 2,n,sum=0;
  17.     int len = s.length();
  18.     for(int i=0;i<len;i++)
  19.     {
  20.       n=0;
  21.       if(isdigit(s[i]))
  22.        { n=s[i]-48;
  23.          sum+=n;
  24.          if(n+1>base) base=n+1;
  25.        }
  26.       else if(isupper(s[i]))
  27.       { n=s[i]-'A'+10;
  28.         sum+=n;
  29.         if(n+1>base) base=n+1;
  30.       }
  31.       else if(islower(s[i]))
  32.       { n=s[i]-'a'+36;
  33.         sum+=n;
  34.         if(n+1>base) base=n+1;
  35.       }
  36.     }
  37.     bool flag;
  38.      for(int j = base;n<=62;j++)
  39.       if(sum%(j-1)==0)
  40.         {printf("%d\n",j);
  41.          flag=true;
  42.          break;
  43.         }
  44.     if(!flag) printf("such number is impossible!\n");
  45.    s.clear();
  46.   }
  47. return 0;
  48. }
clone this paste RAW Paste Data