Advertisement
Patrickmeme

Anaf

Mar 31st, 2023
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. unsigned int v[10002];
  4.  
  5. void adunare (unsigned int a){
  6.     int i;
  7.     v[1]+=a;
  8.     i=1;
  9.     while(v[i]>=10){
  10.         v[i+1]+=v[i]/10;;
  11.         v[i]%=10;
  12.         if(i==v[0])
  13.             v[0]++;
  14.         i++;
  15.     }
  16. }
  17. void inmultire (unsigned int a){
  18.     int i;
  19.     for(i=1;i<=v[0];i++)
  20.         v[i]*=a;
  21.     for(i=1;i<=v[0];i++){
  22.         if(v[i]>=10){
  23.             v[i+1]+=v[i]/10;;
  24.             v[i]%=10;
  25.             if(i==v[0])
  26.                 v[0]++;
  27.         }
  28.     }
  29. }
  30. void impartire(unsigned int a)
  31. {
  32.     int rest,i;
  33.     rest=0;
  34.     for(i=v[0];i>=1;i--){
  35.         v[i]+=rest;
  36.         rest=v[i]%a;
  37.         v[i]/=a;
  38.         rest=rest*10;
  39.     }
  40.     while (v[0]>1 && 0==v[v[0]])
  41.         v[0]--;
  42. }
  43. int rest(unsigned int a)
  44. {
  45.     int rest,i;
  46.     rest=0;
  47.     for(i=v[0];i>=1;i--){
  48.         v[i]+=rest;
  49.         rest=v[i]%a;
  50.         v[i]/=a;
  51.         rest=rest*10;
  52.     }
  53.     while (v[0]>1 && 0==v[v[0]])
  54.         v[0]--;
  55.     return rest/10;
  56. }
  57. int main()
  58. {
  59.     ifstream cin("anaf.in");
  60.     ofstream cout("anaf.out");
  61.     unsigned int a,n,i,j;
  62.     char cer;
  63.     string s;
  64.     cin>>s;
  65.  
  66.     reverse(s.begin(),s.end());
  67.     v[0]=s.size();
  68.     for(i=1;i<=s.size();i++)
  69.         v[i]=s[i-1]-'0';
  70.     cin>>n;
  71.     for(i=0;i<n;i++){
  72.         cin>>cer>>a;
  73.         if(cer=='+'){
  74.             adunare(a);
  75.         }else if(cer=='*'){
  76.             inmultire(a);
  77.         }else if(cer=='/'){
  78.             impartire(a);
  79.         }else if(cer=='%'){
  80.             a=rest(a);
  81.  
  82.             v[0]=0;
  83.             if(a==0){
  84.                 v[0]=1;v[1]=0;
  85.             }
  86.             while(a>0){
  87.                 v[0]++;
  88.                 v[v[0]]=a%10;
  89.                 a/=10;
  90.             }
  91.         }
  92.  
  93.     }
  94.     for(j=v[0];j>0;j--)
  95.         cout<<v[j];
  96.     return 0;
  97. }
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement