-
/* * @Description: 到底有多二 * @version: * @Author: * @Date: 2021-03-24 12:37:49 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-24 15:56:07 */ // TODO:两个测试点未通过,-3 #include <iostream> #include <string> #include <stdio.h> using namespace std; int main(void) { string num; cin >> num; double degree = 1.0; if (num[0] == '-') { degree *= 2; num.erase(num.begin(), num.begin() + 1); } while (true) { if (num[0] == '0') num.erase(num.begin(), num.begin() + 1); else break; } if ((num[num.length() - 1] - '0') % 2 == 0) degree *= 1.5; int num_two = 0; for (int i = 0; i < num.length(); i++) { if (num[i] == '2') num_two++; } // NOTE:输出百分号的方法 printf("%.2lf%%\n", (double)num_two / num.length() * degree * 100); system("pause"); return 0; }
-
/* * @Description: 大笨钟 * @version: * @Author: * @Date: 2021-03-24 12:58:54 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-24 13:07:22 */ #include <iostream> #include <stdio.h> using namespace std; int main(void) { int hour, minute; scanf("%d:%d", &hour, &minute); if (hour <= 12) { printf("Only %02d:%02d. Too early to Dang.\n", hour, minute); } else { hour -= 12; if (!minute) { for (int i = 0; i < hour; i++) printf("Dang"); printf("\n"); } else { for (int i = 0; i <= hour; i++) printf("Dang"); printf("\n"); } } system("pause"); return 0; }
-
/* * @Description: 划拳 * @version: * @Author: * @Date: 2021-03-24 13:09:52 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-24 13:19:07 */ #include <iostream> using namespace std; int main(void) { int max1, max2; cin >> max1 >> max2; int n; cin >> n; int jia_han, jia_hua, yi_han, yi_hua; int drink_jia = 0, drink_yi = 0; for (int i = 0; i < n; i++) { cin >> jia_han >> jia_hua >> yi_han >> yi_hua; if (jia_hua == yi_hua) continue; if (jia_han + yi_han == jia_hua) drink_jia++; else if (jia_han + yi_han == yi_hua) drink_yi++; if (drink_jia == max1 + 1 || drink_yi == max2 + 1) break; } if (drink_jia == max1 + 1) { cout << "A\n" << drink_yi << endl; } else { cout << "B\n" << drink_jia << endl; } system("pause"); return 0; }
-
/* * @Description: 帅到没朋友 * @version: * @Author: * @Date: 2021-03-24 13:19:47 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-24 15:05:23 */ // TODO:来源于网络 #include <iostream> using namespace std; int vis[100009], isoutput[100009]; int main(void) { int n; cin >> n; int k; for (int i = 1; i <= n; i++) { cin >> k; int t; for (int j = 1; j <= k; j++) { cin >> t; if (k > 1) vis[t] = 1; } } int m, ishave = 0, flag = 0; cin >> m; for (int i = 1; i <= m; i++) { int t; cin >> t; if (!vis[t] && !isoutput[t]) { if (flag) cout << " "; else flag = 1; printf("%05d", t); isoutput[t] = 1; } } if (!flag) cout << "No one is handsome" << endl; return 0; }
-
/* * @Description: 重要的事情说三遍 * @version: * @Author: * @Date: 2021-03-24 13:56:38 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-24 13:57:51 */ #include <iostream> using namespace std; int main(void) { cout << "I'm gonna WIN!\nI'm gonna WIN!\nI'm gonna WIN!\n"; return 0; }
-
/* * @Description: 奇偶分家 * @version: * @Author: * @Date: 2021-03-24 13:58:40 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-24 14:02:06 */ #include <iostream> using namespace std; int main(void) { int num_even = 0, num_odd = 0; int n; cin >> n; for (int i = 0; i < n; i++) { int num; cin >> num; if (num & 1) num_odd++; else num_even++; } cout << num_odd << " " << num_even << endl; system("pause"); return 0; }
-
/* * @Description: 输出GPLT * @version: * @Author: * @Date: 2021-03-24 14:04:00 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-24 14:22:25 */ #include <iostream> #include <string> #include <unordered_map> #include <algorithm> using namespace std; int main(void) { string str, res; unordered_map<char, int> m; m['G'] = 0; m['P'] = 0; m['L'] = 0; m['T'] = 0; cin >> str; for (int i = 0; i < str.length(); i++) str[i] = toupper(str[i]); for (int i = 0; i < str.length(); i++) { if (str[i] == 'G' || str[i] == 'P' || str[i] == 'L' || str[i] == 'T') { res.insert(res.end(), str[i]); m[str[i]]++; } } while (true) { if (m['G']) { cout << "G"; m['G']--; } if (m['P']) { cout << "P"; m['P']--; } if (m['L']) { cout << "L"; m['L']--; } if (m['T']) { cout << "T"; m['T']--; } if (!m['G'] && !m['P'] && !m['L'] && !m['T']) break; } cout << endl; system("pause"); return 0; }
-
/* * @Description: 后天 * @version: * @Author: * @Date: 2021-03-24 14:23:03 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-24 14:27:11 */ #include <iostream> using namespace std; int main(void) { int num; cin >> num; num += 2; if (num > 7) num -= 7; cout << num << endl; system("pause"); return 0; }
-
/* * @Description: 正整数A+B * @version: * @Author: * @Date: 2021-03-24 14:30:11 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-24 15:10:10 */ // TODO:一个测试点未通过,-2 #include <iostream> #include <ctype.h> #include <string> using namespace std; bool check(string str) { for (int i = 0; i < str.length(); i++) { if (!isdigit(str[i])) return false; } return true; } int main(void) { string str1, str2; cin >> str1 >> str2; if (check(str1) && check(str2)) { // NOTE:string->int int num1 = stoi(str1); int num2 = stoi(str2); if (num1 < 1 || num1 > 1000) { cout << "? + "; if (num2 < 1 || num2 > 1000) cout << "? = ?" << endl; else cout << num2 << " = ?" << endl; } else if (num2 < 1 || num2 > 1000) cout << num1 << " + " << "? = ?" << endl; else cout << num1 << " + " << num2 << " = " << num1 + num2 << endl; } else if (check(str1) && !check(str2)) { cout << str1 << " + ? = ?" << endl; } else if (!check(str1) && check(str2)) cout << "? + " << str2 << " = ?" << endl; else cout << "? + ? = ?" << endl; system("pause"); return 0; }
-
/* * @Description: 竖向输出I Love GPLT * @version: * @Author: * @Date: 2021-03-24 15:06:15 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-24 15:08:51 */ #include <iostream> #include <string> using namespace std; int main(void) { string str = "I Love GPLT"; for (int i = 0; i < str.length(); i++) cout << str[i] << endl; system("pause"); return 0; }
-
/* * @Description: 出租 * @version: * @Author: * @Date: 2021-03-24 15:10:25 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-24 15:34:53 */ #include <iostream> #include <vector> #include <set> #include <algorithm> #include <string> using namespace std; bool cmp(char x, char y) { return x > y; } int get_index(vector<char> v, char c) { for (int i = 0; i < v.size(); i++) { if (v[i] == c) return i; } return -1; } int main(void) { string str; cin >> str; vector<char> v; set<char> s; for (int i = 0; i < str.length(); i++) s.insert(s.end(), str[i]); set<char>::iterator i; for (i = s.begin(); i != s.end(); i++) v.push_back(*i); sort(v.begin(), v.end(), cmp); cout << "int[] arr = new int[]{"; vector<char>::iterator it; for (it = v.begin(); it != v.end() - 1; it++) { cout << *it << ", "; } cout << *it << "};" << endl; cout << "int[] index = new int[]{"; for (int i = 0; i < str.length() - 1; i++) { cout << get_index(v, str[i]) << ", "; } cout << get_index(v, str[str.length() - 1]) << "};" << endl; system("pause"); return 0; }
-
/* * @Description: 判断素数 * @version: * @Author: * @Date: 2021-03-24 15:35:50 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-24 15:49:24 */ #include <iostream> #include <math.h> using namespace std; bool judgePrime(long num) { if(num<=1) return false; for (int i = 2; i <= sqrt(num); i++) { if ((num % i)==0) return false; } return true; } int main(void) { int n; cin >> n; for (int i = 0; i < n; i++) { long num; cin >> num; if (judgePrime(num)) cout << "Yes" << endl; else cout << "No" << endl; } system("pause"); return 0; }
-
/* * @Description: 是不是太胖了 * @version: * @Author: * @Date: 2021-03-24 15:49:36 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-24 15:53:51 */ #include <iostream> #include <stdio.h> using namespace std; int main(void) { int height; cin >> height; height -= 100; printf("%.1f\n", height * 0.9 * 2); system("pause"); return 0; }
-
/* * @Description: 一帮一 * @version: * @Author: * @Date: 2021-03-24 15:54:36 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-24 16:22:47 */ #include <iostream> #include <vector> #include <string> using namespace std; struct student { int gender; string name; }; int main(void) { int n; cin >> n; vector<struct student> student; for (int i = 0; i < n; i++) { int gender; string name; cin >> gender >> name; struct student s; s.gender = gender; s.name = name; student.push_back(s); } while (!student.empty()) { int gender = student[0].gender; vector<struct student>::iterator it; for (it = student.end()-1; it >= student.begin(); it--) { if (it->gender ^ gender) { cout << student[0].name << " " << it->name << endl; student.erase(it); break; } } student.erase(student.begin()); } system("pause"); return 0; }
-
/* * @Description: 到底是不是太胖了 * @version: * @Author: * @Date: 2021-03-24 21:40:43 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-24 21:56:52 */ #include <iostream> #include <math.h> using namespace std; int main(void) { int n; cin >> n; for (int i = 0; i < n; i++) { int height, weight; cin >> height >> weight; double standard = (height - 100) * 0.9 * 2; if (abs(weight - standard) < standard * 0.1) cout << "You are wan mei!" << endl; else if (weight - standard >= standard * 0.1) cout << "You are tai pang le!" << endl; else if (standard - weight >= standard * 0.1) cout << "You are tai shou le!" << endl; } system("pause"); return 0; }
-
/* * @Description: Left-pad * @version: * @Author: * @Date: 2021-03-24 21:57:03 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-03-24 22:08:19 */ #include <iostream> #include <string> using namespace std; int main(void) { int n; char ch; cin >> n >> ch; string str; getchar(); getline(cin, str, '\n'); if (n >= str.length()) str.insert(str.begin(), n - str.length(), ch); else str.erase(str.begin(), str.end() - n); cout << str << endl; system("pause"); return 0; }
团体程序设计天梯赛-练习集 L1-017——L1-032
最新推荐文章于 2022-10-05 09:38:23 发布