fork download
  1. #include<iostream>
  2. #include<stack>
  3. #include<string.h>
  4. using namespace std;
  5. void multiply(string str,int l){
  6. long long c=0,k=0,i,a;
  7. string str3;
  8. for(i=l-1;i>=0;i--){
  9. a=str[i]-'0';
  10. str3[k++]=((c+(a*2))%10)+'0';
  11. c=(c+(a*2)) /10;
  12. }
  13. if(c){
  14. str3[k]=c+'0';
  15. k=k+1;
  16. }
  17. i=0;
  18. if((str3[i]-'0')>=2)
  19. str3[i]=str3[i]-2;
  20. else{
  21. str3[i]=str3[i]+8;
  22. i++;
  23. while(str3[i]=='0')
  24. {
  25. str3[i]='9';
  26. i++;
  27. }
  28. str3[i]=str3[i]-1;
  29. }
  30. i=k-1;
  31. while (str3[i]=='0') i--;
  32. for(;i>=0;i--)
  33. cout<<str3[i];
  34. cout<<"\n";
  35. }
  36. int main(){
  37. string n;
  38. while(cin>>n){
  39. if(n=="1")
  40. cout<<"1\n";
  41. else
  42. multiply(n,n.length());
  43. }
  44.  
  45.  
  46.  
  47.  
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0s 3436KB
stdin
5
stdout
8