#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <sstream>
#include <list>
using namespace std;
int main() {
int n, k;
cin >> n;
cin >> k;
string first;
list<string> all;
ostringstream oss;
int temp;
for (int i = 0; i < n; i++) {
std::cin >> temp;
oss << temp;
}
oss << 1;
first.append(oss.str());
all.push_back(first);
string previous = first;
for (int j = 1; j < k; ++j) {
oss.str(string());
int a;
char b;
cin >> a;
cin >> b;
previous[a-1]=b;
string current = previous;
oss << (j+1);
current[n]=oss.str()[0];
all.push_back(current);
previous = current;
}
all.sort();
list<string>::iterator it;
for(it = all.begin(); it != all.end(); ++it){
cout << (*it)[n] << " ";
}
return 0;
}
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 43 44 45 46 47 48 49 | #include <iostream> #include <math.h> #include <vector> #include <string> #include <sstream> #include <list> using namespace std; int main() { int n, k; cin >> n; cin >> k; string first; list<string> all; ostringstream oss; int temp; for (int i = 0; i < n; i++) { std::cin >> temp; oss << temp; } oss << 1; first.append(oss.str()); all.push_back(first); string previous = first; for (int j = 1; j < k; ++j) { oss.str(string()); int a; char b; cin >> a; cin >> b; previous[a-1]=b; string current = previous; oss << (j+1); current[n]=oss.str()[0]; all.push_back(current); previous = current; } all.sort(); list<string>::iterator it; for(it = all.begin(); it != all.end(); ++it){ cout << (*it)[n] << " "; } return 0; } |
English