# 第一次编程作业

Github链接地址 https://github.com/users/1458008768/projects/1

1.记录自己的代码行数，需求分析时间，编码时间。

2.分解需求的思路，分解成多个模块，并阐述为什么这么分，优势在哪，可以附上代码片段。

# include

using namespace std;
int toint(string value) {
int len = value.size(), a = 0;
for (int i = 0; i < len; i+=2) {
if (value.substr(i, 2) == "零") a = a10 + 0;
if (value.substr(i, 2) == "一") a = a
10 + 1;
if (value.substr(i, 2) == "二") a = a10 + 2;
if (value.substr(i, 2) == "三") a = a
10 + 3;
if (value.substr(i, 2) == "四") a = a10 + 4;
if (value.substr(i, 2) == "五") a = a
10 + 5;
if (value.substr(i, 2) == "六") a = a10 + 6;
if (value.substr(i, 2) == "七") a = a
10 + 7;
if (value.substr(i, 2) == "八") a = a10 + 8;
if (value.substr(i, 2) == "九") a = a
10 + 9;
if (value.substr(i, 2) == "十") a = a*10 + 10;
}
return a;
}
int main() {
map<string, int> mp;
string var, value, word, oper, cmp, other;
string num[12] = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"};
while (cin >> word) {
if (word == "整数") {
cin >> var >> other >> value;
mp[var] = toint(value);
} else if (word == "看看") {
cin >> var;
if (!mp.count(var)) {
if (var[0] == '"' && var[var.size()-1] == '"')
cout << var.substr(1,var.size()-2) << endl;
continue;
}
int temp = abs(mp[var]);
if (mp[var] < 0) cout << "负";
if (temp <= 10) {
cout << num[temp] << endl;
} else {
int ssum = 0, cnt = 0;
while (temp) {
ssum = ssum * 10 + temp % 10;
temp /= 10;
++cnt;
}
while (cnt--) {
cout << num[ssum%10];
ssum /= 10;
}
cout << endl;
}
} else if (word == "如果") {
string digit, then, s1, s2, s3, s4, s5;
cin >> var >> cmp >> digit;
cin >> then >> s1 >> s2 >> s3 >> s4 >> s5;
if (s1 == "看看") {
int len1 = s2.size()-2;
int len2 = s5.size()-2;
if (cmp == "大于") {
if (mp[var] > toint(digit)) cout << s2.substr(1, len1) << endl;
else cout << s5.substr(1, len2) << endl;
} else if (cmp == "小于") {
if (mp[var] < toint(digit)) cout << s2.substr(1, len1) << endl;
else cout << s5.substr(1, len2) << endl;
}
} else {
if (cmp == "大于") {
if (mp[var] > toint(digit)) {
if (s2 == "减少") {
mp[s1] -= toint(s3);
} else if (s2 == "增加") {
mp[s1] += toint(s3);
}
} else;
} else if (cmp == "小于") {
if (mp[var] < toint(digit)) {
if (s2 == "减少") {
mp[s1] -= toint(s3);
} else if (s2 == "增加") {
mp[s1] += toint(s3);
}
} else;
}
}
} else if (mp.count(word)) {
cin >> oper >> value;
if (oper == "减少") {
mp[word] -= toint(value);
} else if (oper == "增加") {
mp[word] += toint(value);
}
}
}
return 0;
}

3.不足之处

github desktop还不会使用。

posted @ 2020-02-09 15:45  Flawlessxx  阅读(172)  评论(1编辑  收藏  举报