C.cpp 997 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // Created by jal on 2019-04-02.
  3. //
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. int main()
  7. {
  8. string a;
  9. while(cin>>a)
  10. {
  11. stack<int> data;
  12. string tmp;
  13. int len = a.size();
  14. int yushu,zhi,n_c;
  15. while(1)
  16. {
  17. string b;
  18. if (a[0] == '1'&&a.size() == 1)
  19. {
  20. data.push(1);
  21. break;
  22. }
  23. zhi = a[0] - 48;
  24. n_c = zhi/2;
  25. yushu = zhi%2;
  26. tmp = n_c+48;
  27. if (tmp != "0")
  28. b.append(tmp);
  29. for (int i = 1;a[i] != '\0';i++)
  30. {
  31. zhi = a[i]-48;
  32. n_c = (yushu*10 + zhi)/2;
  33. yushu = (yushu*10 + zhi)%2;
  34. tmp = n_c+48;
  35. b.append(tmp);
  36. }
  37. data.push(yushu);
  38. a = b;
  39. }
  40. //data.pop();
  41. while(!data.empty())
  42. {
  43. cout<<data.top();
  44. data.pop();
  45. }
  46. cout<<endl;
  47. }
  48. return 0;
  49. }