Kiri3L

Untitled

Nov 21st, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. struct phones{
  8. string name;
  9. string phone;
  10. };
  11.  
  12. void print_array(vector<phones> ph, int n){
  13. for(int i = 0; i < n; i++){
  14. cout << ph[i].name << " " << ph[i].phone << "\n";
  15. }
  16. cout << "\n";
  17. }
  18.  
  19. bool comp(phones p1, phones p2){
  20. return p1.name.compare(p2.name);
  21. }
  22.  
  23. int main() {
  24. setlocale(LC_ALL,"RUS");
  25. int n;
  26. cin >> n;
  27.  
  28.  
  29. vector<phones> ph;
  30.  
  31. string name;
  32. string phone;
  33.  
  34. for(int i = 0; i < n; i++){
  35. cin >> name;
  36. cin >> phone;
  37. ph.push_back({name,phone});
  38. }
  39.  
  40. print_array(ph,n);
  41.  
  42. sort(ph.begin(),ph.end(), comp);
  43.  
  44. print_array(ph,n);
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment