PAT (Basic) 1016~1020

来源:互联网 发布:linux 查看vnc服务 编辑:程序博客网 时间:2024/04/29 05:23

1016. 部分A+B (15)

#include <iostream>#include <string>using namespace std;int main(){string a, b;int da, db;int pa = 0, pb = 0;cin >> a >> da >> b >> db;int len1 = a.length();int len2 = b.length();for (int i = 0; i < len1; i++){if (a[i] - '0' == da){pa *= 10;pa += da;}}for (int i = 0; i < len2; i++){if (b[i] - '0' == db){pb *= 10;pb += db;}}cout << pa + pb << endl;return 0;}

1017. A除以B (20)

#include <iostream>#include <string>#include <vector>using namespace std;int main(){string a;int b;cin >> a >> b;vector<int> q;if (a.length() == 1){if (a[0] - '0' < b){cout << "0 " << a[0] - '0' << endl;}else if (a[0] - '0' >= b){cout << "1 " << a[0] - '0' - b << endl;}}else{int tmpa = (a[0] - '0') * 10 + a[1] - '0';q.push_back(tmpa / b);int tmpr = tmpa % b;for (int i = 2; i < a.length(); i++){tmpa = tmpr * 10 + a[i] - '0';q.push_back(tmpa / b);tmpr = tmpa % b;}vector<int> ::iterator it;for (it = q.begin(); it != q.end(); ++it)cout << *it;cout << " " << tmpr << endl;}return 0;}

1018. 锤子剪刀布 (20)

#include <iostream>#include <vector>using namespace std;int main(){int n;cin >> n;char c1, c2;int win = 0, tie = 0, fail = 0;int winc1 = 0, winj1 = 0, winb1 = 0;int winc2 = 0, winj2 = 0, winb2 = 0;for (int i = 0; i < n; i++){cin >> c1 >> c2;if (c1 == c2){tie++;}else if (c1 == 'C' && c2 == 'J'){win++;winc1++;}else if (c1 == 'C' && c2 == 'B'){fail++;winb2++;}else if (c1 == 'J' && c2 == 'C'){fail++;winc2++;}else if (c1 == 'J' && c2 == 'B'){win++;winj1++;}else if (c1 == 'B' && c2 == 'C'){win++;winb1++;}else if (c1 == 'B' && c2 == 'J'){fail++;winj2++;}}cout << win << " " << tie << " " << fail << endl;cout << fail << " " << tie << " " << win << endl;if (winb1 >= winc1 && winb1 >= winj1)cout << "B";else if (winc1 > winb1 && winc1 >= winj1)cout << "C";else if (winj1 > winb1 && winj1 > winc1)cout << "J";cout << " ";if (winb2 >= winc2 && winb2 >= winj2)cout << "B";else if (winc2 > winb2 && winc2 > winj2)cout << "C";else if (winj2 > winb2 && winj2 > winc2)cout << "J";cout << endl;return 0;}

1019. 数字黑洞 (20)

同PAT-A-1069. The Black Hole of Numbers (20) 见:http://blog.csdn.net/hale1007/article/details/20251397

1020. 月饼 (25)

同PAT-A-1070. Mooncake (25) 见:http://blog.csdn.net/hale1007/article/details/20455225
0 0