Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<vector>
- #include<map>
- using namespace std;
- /*еще на контейнеры:
- дано n строк. Bывести для каждой буквы алфавита число строк, начинающихся с этой буквы, и сами строки*/
- int main()
- {
- int n;
- cin >> n;
- map<char, vector<string> > a;
- for(int i = 0; i < n; i++)
- {
- string s;
- cin >> s;
- int it = s[0];
- if(it >= 97)
- {
- it-=32;
- }
- if(a.find(it)==a.end())
- {
- vector<string> st;
- st.push_back(s);
- a.insert({it, st});
- }
- else
- {
- a[it].push_back(s);
- }
- }
- for(int i = 65; i<=90; i++)
- {
- if(a.count(i)==0)
- {
- cout << char(i) << ": " << 0 << "\n";
- }
- else
- {
- cout << char(i) << ": " << a[i].size() << "\n";
- for(vector<string>::iterator it = a[i].begin(); it != a[i].end(); it++)
- {
- cout << *it << "\n";
- }
- }
- }
- return 0;
- }
Advertisement
Advertisement