Advertisement
tumaryui

Untitled

Sep 17th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. const int MAXKEY = 999999 + 1;
  6. const int MAXN = 1000000;
  7. const int LEN = 2048;
  8. struct Pair
  9. {
  10. Pair() {}
  11. Pair(int k, char *v) {
  12. key = k;
  13. val = v;
  14. }
  15. ~Pair() {}
  16.  
  17. int key;
  18. char *val;
  19. };
  20.  
  21. Pair arr[MAXN], res[MAXN];
  22. int cnt[MAXKEY], pref[MAXKEY];
  23.  
  24. int main() {
  25. int key;
  26. char val[LEN];
  27. int n = 0;
  28. while(scanf("%d%s", &key, val) > 0) {
  29. arr[n] = Pair(key, val);
  30. cnt[key]++;
  31. n++;
  32. }
  33. for(int i = 0; i < n; i++) {
  34. printf("%s\n", arr[i].val);
  35. }
  36. for(int i = 0; i < MAXKEY; i++) {
  37. pref[i] = cnt[i];
  38. if(i > 0) {
  39. pref[i] += pref[i - 1];
  40. }
  41. }
  42. for(int i = n - 1; i >= 0; i--) {
  43. res[pref[arr[i].key] - 1] = arr[i];
  44. pref[arr[i].key]--;
  45. }
  46. for(int i = 0; i < n; i++) {
  47. if(res[i].key == 0) {
  48. printf("00000");
  49. } else {
  50. for(int j = 0; j < (6 - (1 + int(log10(res[i].key)))); j++) {
  51. printf("0");
  52. }
  53. }
  54. printf("%d %s\n", res[i].key, res[i].val);
  55. }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement