【CPE】一顆星選集(Part 3) | C++

更新於 發佈於 閱讀時間約 6 分鐘

List of Conquests

題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=16&page=show_problem&problem=1361

#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://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=12&page=show_problem&problem=949

中文題目: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://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=14&page=show_problem&problem=1163

中文題目: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;
}


留言
avatar-img
留言分享你的想法!
avatar-img
Jim的沙龍
0會員
31內容數
Jim的沙龍的其他內容
2025/08/13
The 3n + 1 problem 題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=36#google_vignette 中文題目
2025/08/13
The 3n + 1 problem 題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=36#google_vignette 中文題目
2025/08/12
Vito's family 題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=12&page=show_problem&problem=982 中文題目:https://zerojudge.
2025/08/12
Vito's family 題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=12&page=show_problem&problem=982 中文題目:https://zerojudge.
2025/08/12
智能晶片是什麼呢? 在邊緣運算中,有一個重要的零組件,就是智能晶片。在無人機上要有一個智能晶片,才能達到即時辨識目標的判斷。 傳統的晶片所做的有加、減、乘、除的運算。而智能晶片是通過智能化的推理給出一個結果。 傳統的晶片中有三個重要的單元,算術邏輯運算單元(ALU)、數學運算單元(MU)、記憶
2025/08/12
智能晶片是什麼呢? 在邊緣運算中,有一個重要的零組件,就是智能晶片。在無人機上要有一個智能晶片,才能達到即時辨識目標的判斷。 傳統的晶片所做的有加、減、乘、除的運算。而智能晶片是通過智能化的推理給出一個結果。 傳統的晶片中有三個重要的單元,算術邏輯運算單元(ALU)、數學運算單元(MU)、記憶
看更多