- 時間限制:?
- 1000ms 內存限制:
- 65536kB
- 描述
- 有些語言中表達式的運算符使用字符串表示,例如用mul代表*,用div代表/,用add代表+,用sub代表-,用mod代表%。 輸入
- 第一行為表達式的個數n。其余n行每行一個表達式,表達式由兩個整數及其中間的運算符字符串表示。 輸出
- 輸出為n行,每行是對應表達式的值。注意,此處要求的所有運算均為整數運算。 樣例輸入
-
5345 mul 1223945 div 12321 add 343340 sub 211377 mod 27
樣例輸出 -
4209032866412926
(1)、源代碼:
#include<iostream>
#include<string>
?
usingnamespacestd;
?
intmain()
{
????????????????intn, a, b;
????????????????string str;
?
????????????????cin >> n;
????????????????while(n-- > 0)
????????????????{
????????????????????????????????cin >> a >> str >> b;
????????????????????????????????if(str =="mul")
????????????????????????????????????????????????cout << a*b << endl;
????????????????????????????????elseif(str =="div")
????????????????????????????????????????????????cout << a / b << endl;
????????????????????????????????elseif(str =="add")
????????????????????????????????????????????????cout << a + b << endl;
????????????????????????????????elseif(str =="sub")
????????????????????????????????????????????????cout << a - b << endl;
????????????????????????????????elseif(str =="mod")
????????????????????????????????????????????????cout << a % b << endl;
????????????????}
????????????????return0;
}
(2)、解題思路:略
(3)、可能出錯:略