-
/* * @Description: * @version: * @Author: * @Date: 2021-03-26 08:24:48 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-26 09:29:26 */ #include <iostream> #include <algorithm> #include <vector> #include <map> using namespace std; // TODO:未做 int main(void) { int n; cin >> n; vector<int> v; map<int, int> m; for (int i = 0; i < n; i++) { int num; cin >> num; m[num] = i + 1; v.push_back(num); } int min = m.begin()->first; for (int i = 0; i < v.size(); i++) { n = v.size(); if (n == 1) n = 2; int start = i + 1; cout << "#" << i + 1 << endl; for (int j = 0; j < v[i]; j++) { if (j == min) { int count = 0; for (int l = 0; l < v.size(); l++) if (v[l] == min) count++; n -= count; m.erase(m.begin()); } if (n < 2) n = 2; for (int k = 0; k < 10; k++) { if (k == 9) cout << start; else cout << start << " "; start += n; } cout << endl; } } system("pause"); return 0; }
-
/* * @Description: 倒数第n个字符串 * @version: * @Author: * @Date: 2021-03-26 08:40:37 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-26 13:42:29 */ #include <iostream> #include <string> using namespace std; int main(void) { int n, l; cin >> n >> l; string str; str.append(n, 'z'); int index = str.length() - 1; for (int i = 0; i < l - 1; i++) { if (str[str.length() - 1] == 'a') { for (int j = str.length() - 1;; j--) { if (str[j] == 'a') str[j] = 'z'; else { str[j]--; break; } } } else str[str.length() - 1]--; } cout << str << endl; system("pause"); return 0; }
-
/* * @Description: 打折 * @version: * @Author: * @Date: 2021-03-26 13:42:40 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-26 13:42:53 */ #include <iostream> #include <stdio.h> using namespace std; int main(void) { int money, discount; cin >> money >> discount; printf("%.2f\n", money * 0.1 * discount); return 0; }
-
/* * @Description: 2018我们要赢 * @version: * @Author: * @Date: 2021-03-26 13:43:08 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-26 13:43:26 */ #include <iostream> using namespace std; int main(void) { cout << "2018\nwo3 men2 yao4 ying2 !\n"; return 0; }
-
/* * @Description: 电子汪 * @version: * @Author: * @Date: 2021-03-26 13:43:33 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-26 13:43:52 */ #include <iostream> using namespace std; int main(void) { int a, b; cin >> a >> b; for (int i = 0; i < a + b; i++) { if (i == a + b - 1) { cout << "Wang!" << endl; break; } cout << "Wang!"; } return 0; }
-
/* * @Description: 福到了 * @version: * @Author: * @Date: 2021-03-26 13:43:58 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-26 13:44:20 */ #include <string> #include <iostream> using namespace std; bool check(const string str[], int n) { int i = 0, j = n - 1; while (true) { if (i >= j) break; if (str[i] != str[j]) return false; i++; j--; } return true; } int main() { char ch; int n; cin >> ch >> n; string str[n]; getchar(); for (int i = 0; i < n; i++) { getline(cin, str[i], '\n'); } if (check(str, n)) cout << "bu yong dao le\n"; for (int i = n - 1; i >= 0; i--) { for (int j = n - 1; j >= 0; j--) { if (str[i][j] == ' ') cout << str[i][j]; else cout << ch; } cout << endl; } return 0; }
-
/* * @Description: 谁是赢家 * @version: * @Author: * @Date: 2021-03-26 13:44:25 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-26 13:44:45 */ #include <iostream> #include <string> #include <map> using namespace std; int main() { int a, b; cin >> a >> b; map<int, int> m; for (int i = 0; i < 3; i++) { int num; cin >> num; if (m.find(num) != m.end()) m[num]++; else m[num] = 1; } if ((a > b && m.find(0) != m.end()) || m[0] == 3) { cout << "The winner is a: " << a << " + " << m[0] << endl; } else if ((a < b && m.find(1) != m.end()) || m[1] == 3) cout << "The winner is b: " << b << " + " << m[1] << endl; return 0; }
-
/* * @Description: 猜数字 * @version: * @Author: * @Date: 2021-03-26 13:44:50 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-26 13:45:02 */ #include <iostream> #include <map> #include <string> #include <math.h> using namespace std; int main(void) { int n; cin >> n; map<string, int> m; int sum = 0; for (int i = 0; i < n; i++) { string str; int n; cin >> str >> n; m[str] = n; sum += n; } int ave = (int)sum * 1.0 / n / 2; map<string, int>::iterator it; int min = 10000; for (it = m.begin(); it != m.end(); it++) { if (min > abs(it->second - ave)) min = abs(it->second - ave); } for (it = m.begin(); it != m.end(); it++) { if (abs(it->second - ave) == min) { cout << ave << " " << it->first << endl; } } return 0; }
-
/* * @Description: PTA使我精神焕发 * @version: * @Author: * @Date: 2021-03-26 13:45:11 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-26 13:45:29 */ #include <iostream> using namespace std; int main() { cout << "PTA shi3 wo3 jing1 shen2 huan4 fa1 !\n"; return 0; }
-
/* * @Description: 6翻了 * @version: * @Author: * @Date: 2021-03-26 13:45:56 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-26 13:59:23 */ #include <iostream> #include <string> using namespace std; int main() { string str; getline(cin, str); string res; int index = str.find('6'); for (int i = 0; i < str.length(); i++) { if (str[i] != '6') res.insert(res.end(), str[i]); else { int count = 0; for (int j = i;; j++) { if (str[j] != '6') break; count++; } if (count > 3 && count <= 9) res.insert(res.end(), '9'); else if (count > 9) res.append("27"); else if (count <= 3) res.append(count, '6'); i += count - 1; } } cout << res << endl; system("pause"); return 0; }
-
/* * @Description: 敲笨钟 * @version: * @Author: * @Date: 2021-03-26 14:00:17 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-26 14:35:48 */ #include <iostream> #include <string> #include <vector> using namespace std; bool check(string str) { int index_dou = str.find(','); int index_ju = str.length() - 1; if (str[index_dou - 1] == 'g' && str[index_dou - 2] == 'n' && str[index_dou - 3] == 'o' && str[index_ju - 1] == 'g' && str[index_ju - 2] == 'n' && str[index_ju - 3] == 'o') return true; return false; } int main() { int n; vector<string> v; cin >> n; getchar(); for (int i = 0; i < n; i++) { string temp; getline(cin, temp); v.push_back(temp); } for (int i = 0; i < v.size(); i++) { if (!check(v[i])) { cout << "Skipped" << endl; continue; } else { size_t index = v[i].find_last_of(' ', -1); index = v[i].find_last_of(' ', index - 1); index = v[i].find_last_of(' ', index - 1); // cout << index; v[i].erase(v[i].begin() + index, v[i].end()); v[i].append(" qiao ben zhong."); cout << v[i] << endl; } } system("pause"); return 0; }
-
/* * @Description: 心理阴影面积 * @version: * @Author: * @Date: 2021-03-26 14:36:24 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-26 14:39:36 */ #include <iostream> using namespace std; int main(void) { int x, y; cin >> x >> y; cout << 100 * 50 - x * y / 2 - (100 - x) * (100 - y) / 2 << endl; return 0; }
-
/* * @Description: 新胖子公式 * @version: * @Author: * @Date: 2021-03-26 14:49:53 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-26 14:52:34 */ #include <iostream> using namespace std; int main(void) { float weight, height; cin >> weight >> height; float BMI = weight / height / height; printf("%.1f\n", BMI); if (BMI > 25) cout << "PANG" << endl; else cout << "Hai Xing" << endl; return 0; }
-
/* * @Description: 幸运彩票 * @version: * @Author: * @Date: 2021-03-26 14:53:35 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-26 15:01:58 */ #include <iostream> #include <string> using namespace std; int main(void) { int n; cin >> n; for (int i = 0; i < n; i++) { string str; cin >> str; int sum1 = 0, sum2 = 0; sum1 = (str[0] - '0') + (str[1] - '0') + (str[2] - '0'); sum2 = (str[3] - '0') + (str[4] - '0') + (str[5] - '0'); if (sum1 == sum2) cout << "You are lucky!" << endl; else cout << "Wish you good luck." << endl; } return 0; }
-
/* * @Description: 吃鱼还是吃肉 * @version: * @Author: * @Date: 2021-03-26 15:09:58 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-26 15:16:21 */ #include <iostream> using namespace std; int main(void) { int n; cin >> n; for (int i = 0; i < n; i++) { int gender, height, weight; cin >> gender >> height >> weight; if (gender == 0) { if (height == 129) cout << "wan mei! "; else if (height > 129) cout << "ni li hai! "; else if (height < 129) cout << "duo chi yu! "; if (weight == 25) cout << "wan mei!" << endl; else if (weight < 25) cout << "duo chi rou!" << endl; else if (weight > 25) cout << "shao chi rou!" << endl; } else if (gender == 1) { if (height == 130) cout << "wan mei! "; else if (height > 130) cout << "ni li hai! "; else if (height < 130) cout << "duo chi yu! "; if (weight == 27) cout << "wan mei!" << endl; else if (weight < 27) cout << "duo chi rou!" << endl; else if (weight > 27) cout << "shao chi rou!" << endl; } } return 0; }
-
/* * @Description: 估值一亿的AI核心代码 * @version: * @Author: * @Date: 2021-03-26 15:17:02 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-26 17:13:53 */ #include <iostream> #include <string> #include <ctype.h> using namespace std; // TODO:-6分,主要问题在tranverseWord函数内 void eraseblank(string &str) { // 去行首空格 for (int i = 0; i < str.length(); i++) { if (str[i] != ' ') break; else str.erase(str.begin()); } // 去行尾空格 for (int i = str.length() - 1; i >= 0; i--) { if (str[i] != ' ') break; else str.erase(str.end() - 1); } // 去标点符号前的空格 for (int i = 0; i < str.length(); i++) { if (ispunct(str[i])) { for (int j = i - 1;; j--) { if (str[j] != ' ') break; else str.erase(str.begin() + j); } } } // 去连续空格 for (int i = 0; i < str.length(); i++) { if (str[i] == ' ') { int j = i + 1; while (true) { if (str[j] != ' ') break; else { str.erase(str.begin() + j); j--; } j++; } } } } void uppertolower(string &str) { for (int i = 0; i < str.length(); i++) { if (str[i] == 'I') continue; if (isupper(str[i])) str[i] = tolower(str[i]); } } void tranverseword(string &str) { int n = 0; while (true) { if (str.find("can you",n) == string::npos) break; int index = str.find("can you",n); if(index>0) if (str[index - 1] != ' ' && !ispunct(str[index - 1])) { n = index + 1; continue; } if (str[index + 7] == ' ' || ispunct(str[index + 7])) str.replace(str.begin() + index, str.begin() + 7, "I can"); else n++; } n = 0; while (true) { if (str.find("could you") == string::npos) break; int index = str.find("could you"); if (index > 0) if (str[index - 1] != ' ' && !ispunct(str[index - 1])) { n = index + 1; continue; } if (str[index + 9] == ' ' || ispunct(str[index + 9])) str.replace(str.begin() + index, str.begin() + 9, "I could"); else n++; } n = 0; while (true) { if (str.find('I', n) == string::npos) break; int index = str.find('I', n); if (index > 0) if (str[index - 1] != ' ' && !ispunct(str[index - 1])) { n = index + 1; continue; } if (str[index + 2] == 'c'&&str[index + 3] == 'a'&&str[index + 4] == 'n') { n = index + 1; continue; } else if (str[index + 2] == 'c'&&str[index + 3] == 'o') { n = index + 1; continue; } if (str[index + 1] == ' ' || ispunct(str[index + 1])) str.replace(str.begin() + index, str.begin() + +index + 1, "you"); else n++; } n = 0; while (true) { if (str.find("me", n) == string::npos) break; int index = str.find("me", n); if(index>0) if (str[index - 1] != ' ' && !ispunct(str[index - 1])) { n = index + 1; continue; } if (str[index + 2] == ' ' || ispunct(str[index + 2])) str.replace(str.begin() + index, str.begin() + index + 2, "you"); else n++; } n = 0; while (true) { if (str.find('?') == string::npos) break; int index = str.find("?"); str[index] = '!'; } } int main(void) { int n; cin >> n; getchar(); for (int i = 0; i < n; i++) { string str; getline(cin, str, '\n'); cout << str << endl; eraseblank(str); uppertolower(str); tranverseword(str); cout << "AI: " << str << endl; // AI: what Is this prime! you,don't know } system("pause"); return 0; }
团体程序设计天梯赛-练习集 L1-049——L1-064
最新推荐文章于 2024-04-28 15:37:27 发布