fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. struct Data {
  7. char key;
  8. int value;
  9.  
  10. Data(char key, int value)
  11. {
  12. this->key = key;
  13. this->value = value;
  14. }
  15. };
  16.  
  17. inline bool is_greater(const Data& lhs, const Data& rhs) {
  18. return lhs.value > rhs.value;
  19. }
  20.  
  21. void print(const vector<Data>& datas)
  22. {
  23. for (auto& data : datas)
  24. {
  25. printf("%c %d\n", data.key, data.value);
  26. }
  27. }
  28.  
  29. int main() {
  30. // your code goes here
  31.  
  32. vector<Data> datas;
  33.  
  34. for (char ch = 'A'; ch <= 'Z'; ch++)
  35. {
  36. datas.push_back(Data(ch, 1));
  37.  
  38. }
  39.  
  40. std::sort(datas.begin(), datas.end(), is_greater);
  41.  
  42. print(datas);
  43.  
  44. return 0;
  45. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
N 1
Z 1
Y 1
X 1
W 1
V 1
U 1
T 1
S 1
R 1
Q 1
P 1
O 1
A 1
M 1
L 1
K 1
J 1
I 1
H 1
G 1
F 1
E 1
D 1
C 1
B 1