Advertisement
Rimifawfaw

Untitled

Sep 7th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. string ree(string x);
  6.  
  7.  
  8. int main()
  9. {
  10. int x,i;
  11. string s,c;
  12.  
  13. cin>>s >>x;
  14. c = s;
  15. for(i =1;i<x;i++)
  16. {
  17. s+=c;
  18. }
  19. //cout<<s<<endl;
  20. cout<<ree(s)<<endl;
  21. return 0;
  22. }
  23. string ree(string x)
  24. {
  25. // cout<<"size "<<x.size()<<endl;
  26. if(x.length()==1)
  27. {
  28. return x;
  29. }
  30.  
  31.  
  32. if(x.length()>=2)
  33. {
  34. int sum=0;
  35. for(int i=0;i<x.length();i++)
  36. {
  37. sum+= x[i]-'0';
  38. // cout<<sum<<endl;
  39.  
  40. }
  41.  
  42. x = to_string(sum);
  43. return ree(x);
  44.  
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement