fork(4) download
  1. /*
  2. *DIV 2 C.
  3. *LINK:
  4. *nilabja10201992
  5. */
  6. #include <bits/stdc++.h>
  7. using namespace std;
  8. void solve(string str){
  9. int n = str.length();
  10. string str1;
  11. int carry=0;
  12. for(int i=n-1;i>=0;i--){
  13. int a=(str[i]-'0')*2+carry;
  14. str1+=(char)(a%10+'0');
  15. carry=a/10;
  16. //cout<<carry<<" "<<a<<endl;
  17. }
  18. if(carry>0)
  19. str1+=(char)(carry+'0');
  20. //cout<<str1<<endl;
  21. carry=2;
  22. for(int i=0;i<str1.size();i++){
  23. int a=str1[i] - '0';
  24. if(a>1){
  25. str1[i]=(str1[i]- '0' - carry + 10)%10 + '0';
  26. break;
  27. // cout<<str1[i]<<endl;
  28. }
  29. else{
  30. str1[i]=(str1[i]- '0' - carry + 10)%10 + '0';
  31. carry=1;
  32. }
  33. }
  34. reverse(str1.begin(),str1.end());
  35. bool fl=0;
  36. for(int i=0;i<str1.size();i++){
  37. if(str1[i]=='0' && fl==0)
  38. continue;
  39. cout<<str1[i];
  40. fl=1;
  41. }
  42. cout<<endl;
  43. }
  44. int main() {
  45. ios_base::sync_with_stdio(false);
  46. cin.tie(NULL);
  47. string str;
  48. while(cin>>str){
  49. if(str=="1" || str=="0")
  50. cout<<str<<endl;
  51. else
  52. solve(str);
  53. }
  54. //cout<<"Execution time : "<<tick();
  55. return 0;
  56. }
  57.  
Success #stdin #stdout 0s 16064KB
stdin
2
stdout
2