#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<cmath>
using namespace std;
int main() {
map < string, int > num = {{"ling", 0}, { "yi",1 }, { "er",2 }, { "san",3 }, { "si",4 }, { "wu",5 }, { "liu",6 }, { "qi",7 }, { "ba",8 }, { "jiu",9 }};
vector<int> tel;
vector<char> op = { '+','-','*','/','%','t','^'};
string str;
bool flag;
for (int i = 0; i < 11; i++) {
cin >> str;
flag = false;
for (auto it = op.begin(); it != op.end(); it++) {
if (str.find_first_of(*it) != -1) {
flag = true;
int c;
int index = str.find_first_of(*it);
if (*it == 't') {//开方
int a = stoi(str.substr(index+1));
c = sqrt(a);
}
else {
int a = stoi(str.substr(0, index));
int b = stoi(str.substr(index+1));
if (*it == '+') c = a + b;
if (*it == '-') c = a - b;
if (*it == '*') c = a * b;
if (*it == '/') c = a / b;
if (*it == '%') c = a % b;
if (*it == '^') c = pow(a, b);
}
tel.push_back(c);
break;
}
}
if (flag == false) {
if (num.count(str)) {
tel.push_back(num[str]);
}
else {
tel.push_back(stoi(str));//没有运算符,只有数字
}
}
}
for (int i = 0; i < 11; i++) {
cout << tel[i];
}
return 0;
}
PAT B1118 如需挪车请致电
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 包括四个表:学生表(Student)、课程表(Course)、成绩表(Score)以及教师信息表(Teacher)...
- 背景 大家是不是经常会遇到这种情况,分享出去的网页链接在微信里打开会提示“如需访问,请长按网址复制后使用浏览器访问...
- 文 |琉璃苏比 暖小圆:“妈妈,你知道吗?没有孩子的爸爸妈妈会自己去找一个孩子的。”暖小璃:“啊?去哪里找?”暖小...