Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- using namespace std;
- struct phones{
- string name;
- string phone;
- };
- void print_array(vector<phones> ph, int n){
- for(int i = 0; i < n; i++){
- cout << ph[i].name << " " << ph[i].phone << "\n";
- }
- cout << "\n";
- }
- bool comp(phones p1, phones p2){
- return p1.name.compare(p2.name);
- }
- int main() {
- setlocale(LC_ALL,"RUS");
- int n;
- cin >> n;
- vector<phones> ph;
- string name;
- string phone;
- for(int i = 0; i < n; i++){
- cin >> name;
- cin >> phone;
- ph.push_back({name,phone});
- }
- print_array(ph,n);
- sort(ph.begin(),ph.end(), comp);
- print_array(ph,n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment