Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- unsigned int v[10002];
- void adunare (unsigned int a){
- int i;
- v[1]+=a;
- i=1;
- while(v[i]>=10){
- v[i+1]+=v[i]/10;;
- v[i]%=10;
- if(i==v[0])
- v[0]++;
- i++;
- }
- }
- void inmultire (unsigned int a){
- int i;
- for(i=1;i<=v[0];i++)
- v[i]*=a;
- for(i=1;i<=v[0];i++){
- if(v[i]>=10){
- v[i+1]+=v[i]/10;;
- v[i]%=10;
- if(i==v[0])
- v[0]++;
- }
- }
- }
- void impartire(unsigned int a)
- {
- int rest,i;
- rest=0;
- for(i=v[0];i>=1;i--){
- v[i]+=rest;
- rest=v[i]%a;
- v[i]/=a;
- rest=rest*10;
- }
- while (v[0]>1 && 0==v[v[0]])
- v[0]--;
- }
- int rest(unsigned int a)
- {
- int rest,i;
- rest=0;
- for(i=v[0];i>=1;i--){
- v[i]+=rest;
- rest=v[i]%a;
- v[i]/=a;
- rest=rest*10;
- }
- while (v[0]>1 && 0==v[v[0]])
- v[0]--;
- return rest/10;
- }
- int main()
- {
- ifstream cin("anaf.in");
- ofstream cout("anaf.out");
- unsigned int a,n,i,j;
- char cer;
- string s;
- cin>>s;
- reverse(s.begin(),s.end());
- v[0]=s.size();
- for(i=1;i<=s.size();i++)
- v[i]=s[i-1]-'0';
- cin>>n;
- for(i=0;i<n;i++){
- cin>>cer>>a;
- if(cer=='+'){
- adunare(a);
- }else if(cer=='*'){
- inmultire(a);
- }else if(cer=='/'){
- impartire(a);
- }else if(cer=='%'){
- a=rest(a);
- v[0]=0;
- if(a==0){
- v[0]=1;v[1]=0;
- }
- while(a>0){
- v[0]++;
- v[v[0]]=a%10;
- a/=10;
- }
- }
- }
- for(j=v[0];j>0;j--)
- cout<<v[j];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement