标签:ace cin int names ade begin 处理 pre space
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int a, i; vector<int> v; for (i = 0; i < 10; i++) { scanf("%d", &a); v.push_back(a); } sort(v.begin(), v.end()); for (i = 0; i < 10; i++) { cout << v[i]; if (i < 9) cout << ","; } return 0; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; struct student { int age, id; string name, gender; }; bool cmp(student t1, student t2) { if (t1.id != t2.id) return t1.id > t2.id; } int main() { int a, i, j; string s; student stu; vector<student> v; student st[3]; st[0].id = 10; st[0].name = "wes"; st[0].gender = "f"; st[0].age = 23; st[1].id = 20; st[1].name = "erf"; st[1].gender = "f"; st[1].age = 45; st[2].id = 30; st[2].name = "str"; st[2].gender = "t"; st[2].age = 89; v.push_back(st[0]); v.push_back(st[1]); v.push_back(st[2]); while (getline(cin, s)) { string str[4]; if (s[0] == ‘I‘) { int n = (s[1] - ‘0‘) * 10 + (s[2] - ‘0‘); stu.id = n; n = s[s.length() - 1] - ‘0‘ + (s[s.length() - 2] - ‘0‘) * 10; stu.age = n; string ss = ""; for (i = 4; i < s.length(); i++) { if (s[i] == ‘,‘) { stu.name = ss; ss = ""; break; } ss += s[i]; } for (j = i + 1; j < s.length(); j++) { if (s[j] == ‘,‘) { stu.gender = ss; break; } ss += s[j]; } v.push_back(stu); sort(v.begin(), v.end(), cmp); for (i = 0; i < v.size(); i++) { cout << "(" << v[i].id << "," << v[i].name << "," << v[i].gender << "," << v[i].age << ")"; if (i < v.size() - 1) cout << ","; } } if (s[0] == ‘D‘) { int n = (s[1] - ‘0‘) * 10 + (s[2] - ‘0‘); for (i = 0; i < v.size(); i++) { if (v[i].id == n) { v.erase(v.begin() + i); break; } } sort(v.begin(), v.end(), cmp); for (i = 0; i < v.size(); i++) { cout << "(" << v[i].id << "," << v[i].name << "," << v[i].gender << "," << v[i].age << ")"; if (i < v.size() - 1) cout << ","; } } } return 0; }
标签:ace cin int names ade begin 处理 pre space
原文地址:https://www.cnblogs.com/ache/p/12571658.html