#include <bits/stdc++.h> using namespace std; struct word{ int id; vector<int> w; }; bool srt(word a, word b){ for(int i = 0; i < a.w.size(); i++) if(a.w[i] != b.w[i]) return a.w[i] < b.w[i]; return a.id < b.id; } int main(){ ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; int c; string s; vector<word> all; word pom; pom.id = 1; for(int i = 0; i < n; i++){ cin >> c; pom.w.push_back(c); } all.push_back(pom); int x1, x2; for(int i = 0; i < m - 1; i++){ cin >> x1 >> x2; pom.w[x1-1] = x2; pom.id++; all.push_back(pom); } sort(all.begin(), all.end(), srt); for(int i = 0; i < all.size(); i++) cout << all[i].id << " "; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #include <bits/stdc++.h> using namespace std; struct word{ int id; vector<int> w; }; bool srt(word a, word b){ for(int i = 0; i < a.w.size(); i++) if(a.w[i] != b.w[i]) return a.w[i] < b.w[i]; return a.id < b.id; } int main(){ ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; int c; string s; vector<word> all; word pom; pom.id = 1; for(int i = 0; i < n; i++){ cin >> c; pom.w.push_back(c); } all.push_back(pom); int x1, x2; for(int i = 0; i < m - 1; i++){ cin >> x1 >> x2; pom.w[x1-1] = x2; pom.id++; all.push_back(pom); } sort(all.begin(), all.end(), srt); for(int i = 0; i < all.size(); i++) cout << all[i].id << " "; } |