fork download
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<math.h>
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8. int N;
  9. cin >> N;
  10.  
  11. char a, b;
  12. cin >> a >> b;
  13.  
  14. int bin_nums[1005];
  15. int dec_nums[1005] = { 0 };
  16.  
  17. for (int i = 0;i < N;i++) {
  18. cin >> bin_nums[i];
  19.  
  20. int j = 0, rem;
  21. while (bin_nums[i] != 0) {
  22. rem = bin_nums[i] % 10;
  23. bin_nums[i] /= 10;
  24. dec_nums[i] += rem * pow(2, j);
  25. ++j;
  26. }
  27.  
  28. }
  29.  
  30. char table_lets[1005];
  31. for (int i = 0;i < N;i++) {
  32. cin >> table_lets[i];
  33. }
  34.  
  35. if (a == 'A' && b == 'A') {
  36. sort(dec_nums, dec_nums + N);
  37. sort(table_lets, table_lets + N);
  38. for (int i = 0;i < N;i++) { cout << table_lets[i] << dec_nums[i]<< " " << endl; }
  39. }
  40. else if (a == 'A' && b == 'D') {
  41. sort(dec_nums, dec_nums + N);
  42. reverse(table_lets, table_lets + N);
  43. for (int i = 0;i < N;i++) { cout << table_lets[i] << dec_nums[i] << " " << endl; }
  44. }
  45. else if (a == 'D' && b == 'D') {
  46. reverse(dec_nums, dec_nums + N);
  47. reverse(table_lets, table_lets + N);
  48. for (int i = 0;i < N;i++) { cout << table_lets[i] << dec_nums[i] << " " << endl; }
  49. }
  50. else if (a == 'D' && b == 'A') {
  51. reverse(dec_nums, dec_nums + N);
  52. sort(table_lets, table_lets + N);
  53. for (int i = 0;i < N;i++) { cout << table_lets[i] << dec_nums[i] << " " << endl; }
  54. }
  55. return 0;
  56. }
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
Standard output is empty