List of Conquests
#include <iostream>
#include <sstream>
#include <map>
using namespace std;
int main() {
int n;
cin >> n;
map <string, int> mp;
string s;
getline(cin, s);
while (n--) {
getline(cin, s);
stringstream ss(s);
ss >> s;
mp[s]++;
}
for (auto i: mp) {
cout << i.first << " " << i.second << "\n";
}
return 0;
}
What's Cryptanalysis?
中文題目:https://zerojudge.tw/ShowProblem?problemid=c044#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool cmp(pair<int, char> a, pair<int, char> b) {
if (a.first != b.first) return a.first > b.first;
else return a.second < b.second;
}
int main() {
vector <pair<int, char>> v(26);
for (int i=0; i<26; i++) {
v[i] = {0, 'A' + i);
}
int n;
string s;
getline(cin, s);
while (n--) {
getline(cin, s);
for (int i=0; i<s.size(); i++) {
if ('A' <= s[i] && s[i] <= 'Z') {
v[s[i] - 'A'].first++;
}
if ('a' <= s[i] && s[i] <= 'z') {
v[s[i] - 'a'].first++;
}
}
}
sort(v.begin(), v.end(), cmp);
for (auto i: v) {
if (i.first > 0) cout << i.second << " " << i.first << "\n";
}
return 0;
}
Decode the Mad man
中文題目:https://zerojudge.tw/ShowProblem?problemid=e578
#include <iostream>
#include <map>
using namespace std;
int main() {
string s[] = {
"~!@#$%^&*()_+",
"`1234567890-=",
"qwertyuiop[]\\",
"asdfghjkl;'",
"zxcvbnm,./"
};
map <char, char> mp;
for (int i=0; i<5; i++) {
for (int j=2; j<s[i].size(); j++) {
mp[s[i][j]] = s[i][j-2];
}
}
string S;
while (getline(cin, S)) {
for (int i=0; i<S.size(); i++) {
if (S[i] == ' ') cout << " ";
else cout << mp[S[i]];
}
cout << "\n";
}
return 0;
}