Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- const int MAXKEY = 999999 + 1;
- const int MAXN = 1000000;
- const int LEN = 2048;
- struct Pair
- {
- Pair() {}
- Pair(int k, char *v) {
- key = k;
- val = v;
- }
- ~Pair() {}
- int key;
- char *val;
- };
- Pair arr[MAXN], res[MAXN];
- int cnt[MAXKEY], pref[MAXKEY];
- int main() {
- int key;
- char val[LEN];
- int n = 0;
- while(scanf("%d%s", &key, val) > 0) {
- arr[n] = Pair(key, val);
- cnt[key]++;
- n++;
- }
- for(int i = 0; i < n; i++) {
- printf("%s\n", arr[i].val);
- }
- for(int i = 0; i < MAXKEY; i++) {
- pref[i] = cnt[i];
- if(i > 0) {
- pref[i] += pref[i - 1];
- }
- }
- for(int i = n - 1; i >= 0; i--) {
- res[pref[arr[i].key] - 1] = arr[i];
- pref[arr[i].key]--;
- }
- for(int i = 0; i < n; i++) {
- if(res[i].key == 0) {
- printf("00000");
- } else {
- for(int j = 0; j < (6 - (1 + int(log10(res[i].key)))); j++) {
- printf("0");
- }
- }
- printf("%d %s\n", res[i].key, res[i].val);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement