Guest User

ACMP_164

a guest
Mar 16th, 2011
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <string>
  5. #include <sstream>
  6. #define F(i,a,b) for (int i=a; i<=b; i++)
  7. #define Ss stringstream
  8. #define L length()
  9. using namespace std;
  10. string st;
  11.  
  12.       int go(int z)
  13.        {
  14.         int tp=0;
  15.         while (z)
  16.          {
  17.           tp+=(z%10); z/=10;
  18.          }
  19.          if (tp>9) go(tp); else return tp;
  20.        }
  21.  
  22.     bool c(int k)
  23.      {
  24.       int x=0,y=0;
  25.       string s1,s2;
  26.       F(i,0,k-1) s1+=st[i];
  27.       F(i,k,st.L-1) s2+=st[i];
  28.       Ss(s1)>>x; Ss(s2)>>y;
  29.       x=go(x); y=go(y);
  30.       cout<<x<<" "<<y<<endl;
  31.  
  32.       if (x==y) return 1; else
  33.       return 0;
  34.      }
  35.  
  36. int main()
  37. {
  38.  freopen("input.txt","rt",stdin);
  39.  freopen("output.txt","wt",stdout);
  40.  cin>>st;
  41.   F(i,1,st.L-1)
  42.   if (c(i)) cout<<"YES",exit(0);
  43.  cout<<"NO";
  44. }
Advertisement
Add Comment
Please, Sign In to add comment