Monday 23 November 2015

SPOJ SOLUTION : Simple Arithmetic 2 (code: arith2)

/*
Problem:Simple Arithmetics II
Source: Spoj
Type: Ad-hoc
Language: C++
*/

#include <iostream>

using namespace std;

int main(void)
{
    int tc;
    int flag=1;
    long long num1,num2,ans,count;
    char op;

    cin>>tc;
   
     while(tc--)
    {
        flag=1;
        count=0;
        while(flag) //flag checks if '=' is encountered
        {
        count++;
        if(count==1) //count determines if the expression is starting or we are in  middle of the expression to be solved
        {
        //get the expression
        cin>>num1;
        }
        else
        num1=ans;
       
        op=' '; //as expression contains many spaces this is where we avoid spaces
        while(op == ' ')
            cin>>op;
        if(op=='=')
        {
            cout<<ans<<"\n";
            flag=0;
        }
        else
            cin>>num2;
       
        switch(op)
        {
            case  '+' : ans=num1+num2;
                    break;
            case  '-' : ans=num1-num2;
                    break;
            case  '*' : ans=num1*num2;
                    break;
            case  '/' : ans=num1/num2;
                    break;
            default : break;
        }
       
       
        }//while
    }
        return 0;
       
}   

1 comment:

  1. Casino Poker - Bonuses, Codes and Promotions 2021
    All bonus features and promotions are exclusive to Casino Poker players 벳 삼육오 and 포커 페이스 뜻 casinos. 7 포커 족보 These 슬롯 include all free spins, no 인싸 포커 deposit bonuses, and deposit bonus

    ReplyDelete