Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream cin("anaf.in");
- ofstream cout("anaf.out");
- #define NMAX 10000
- int v[NMAX];
- int main(){
- int n, i, t, nr, nrc, j;
- char c, aux;
- cin.get(c);
- nr = 0;
- while(c != '\n'){
- v[nr] = c - '0';
- nr++;
- cin.get(c);
- }
- t = nr - 1;
- i = 0;
- while(i < t){
- aux = v[i];
- v[i] = v[t];
- v[t] = aux;
- i++;
- t--;
- }
- while(nr > 0 && v[nr - 1] == 0){
- nr--;
- }
- cin>>n;
- cin.get();
- for(j = 0;j<n;j++){
- cin.get(c);
- cin>>nrc;
- switch(c){
- case '+':
- for(i = 0;i<nr;i++){
- nrc+=v[i];
- v[i] = nrc % 10;
- nrc /= 10;
- }
- while(nrc > 0){
- v[nr] = nrc % 10;
- nrc /= 10;
- nr++;
- }
- break;
- case '*':
- t = 0;
- for(i = 0;i<nr;i++){
- t+= nrc * v[i];
- v[i] = t % 10;
- t /= 10;
- }
- while(t > 0){
- v[nr] = t % 10;
- t /= 10;
- nr++;
- }
- break;
- case '/':
- t = 0;
- for(i = nr - 1;i>= 0;i--){
- t = t * 10 + v[i];
- v[i] = t / nrc;
- t %= nrc;
- }
- while(nr > 0 && v[nr - 1] == 0){
- nr--;
- }
- break;
- case '%':
- t = 0;
- for(i = nr - 1;i>= 0;i--){
- t = t * 10 + v[i];
- v[i] = t % nrc;
- t %= nrc;
- }
- i = 0;
- while(t > 0){
- v[i] = t % 10;
- t /= 10;
- i++;
- }
- nr = i;
- break;
- }
- cin.get(c);
- }
- cin.close();
- if(nr == 0){
- cout<<0;
- }else{
- for(i = nr - 1;i>= 0;i--){
- cout.put('0' + v[i]);
- }
- }
- cout.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement