题目地址:天梯赛
#include<bits/stdc++.h>
using namespace std;
int main() {
puts("PTA shi3 wo3 jing1 shen2 huan4 fa1 !");
return 0;
}
#include<bits/stdc++.h>
using namespace std;
string s;
unordered_map<int, int> mp;
int cnt;
int main() {
getline(cin, s);
for(int i = 0; i < s.length(); ++i) {
if(s[i] == '6') ++cnt;
else if(cnt) mp[i - 1] = cnt, cnt = 0;
}
if(cnt) mp[s.length() - 1] = cnt;
for(int i = 0; i < s.length(); ++i) {
if(s[i] != '6') {
cout << s[i];
continue;
}
if(mp.count(i)) {
if(mp[i] > 9) cout << 27;
else if(mp[i] > 3) cout << 9;
else {
for(int j = 0; j < mp[i]; ++j) {
cout << 6;
}
}
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
cin >> n, getchar();
while(n--) {
getline(cin, s);
for(int i = 0; i < s.length(); ++i) {
if(s[i] == ',' && s[s.length() - 4] == 'o' && s[s.length() - 3] == 'n' && s[s.length() - 2] == 'g' && s[i - 3] == 'o' && s[i - 2] == 'n' && s[i - 1] == 'g') {
int k = s.length() - 4, cnt = 0;
while(cnt != 3) {
--k;
if(s[k] == ' ') ++cnt;
}
for(int j = 0; j < k + 1; ++j) {
cout << s[j];
}
puts("qiao ben zhong.");
goto here;
}
}
cout << "Skipped\n";
here:;}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
double a, b;
int main() {
cin >> a >> b;
cout << 0.5 * (100 * 100 - (100 - a + b) * 100);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
double w, h;
int main() {
cin >> w >> h;
printf("%.1f\n", w / pow(h, 2));
cout << ((w / pow(h, 2) > 25) ? "PANG" : "Hai Xing");
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
cin >> n;
while(n--) {
cin >> s;
cout << ((s[0] + s[1] + s[2] == s[3] + s[4] + s[5]) ? "You are lucky!" : "Wish you good luck.") << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int n, sex, h, w, bh, bw;
int main() {
cin >> n;
while(n--) {
cin >> sex >> h >> w;
sex ? (bh = 130, bw = 27) : (bh = 129, bw = 25);
if(h == bh) cout << "wan mei! ";
else cout << (h > bh ? "ni li hai!" : "duo chi yu!") << " ";
if(w == bw) cout << "wan mei!\n";
else cout << (w > bw ? "shao chi rou!" : "duo chi rou!") << endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
cin >> n;
getchar();
while (n --) {
getline(cin, s);
cout << s << '\n' << "AI: ";
s = regex_replace(s, regex(R"(\s+)"), " ");
s = regex_replace(s, regex(R"(^\s+|\s+$|\s+(?=\W))"), "");
s = regex_replace(s, regex(R"(\bI\b)"), "mark_mark");
for(auto& x : s) if(x != 'I') x = tolower(x);
s = regex_replace(s, regex(R"(\bcan you\b)"), "I can");
s = regex_replace(s, regex(R"(\bcould you\b)"), "I could");
s = regex_replace(s, regex(R"(mark_mark|\bme\b)"), "you");
s = regex_replace(s, regex(R"(\?)"), "!");
cout << s << '\n';
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int a, b;
unordered_map<int, int> mp;
unordered_set<int> ck;
int check(int x) {
int now = x, cnt = 1;
unordered_set<int> st;
while(x != 1) {
if(mp.count(x)) {
int n = mp[x];
mp.erase(x);
return n + cnt;
}
if(st.count(x)) return -1;
if(x != now) st.insert(x), ++cnt,ck.insert(x);
int mid = 0;
while(x) {
mid += (x % 10) * (x % 10);
x /= 10;
}
x = mid;
}
return cnt;
}
bool is_prime(int x) {
if(x <= 2) return false;
for(int i = 2; i <= sqrt(x); ++i) if(!(x % i)) return false;
return true;
}
int main() {
cin >> a >> b;
for(int i = a; i <= b; ++i) {
int x = check(i);
if(x != -1) mp[i] = x;
}
for(int i = a; i <= b; ++i) {
if(!mp.count(i) || ck.count(i)) continue;
if(is_prime(i)) mp[i] *= 2;
cout << i << " " << mp[i] << endl;
}
if(!mp.size()) cout << "SAD";
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int n, m;
string firstname, lastname, s1, s2, s3, s4;
unordered_map<string, pair<string, char>> mp;
bool find(string s1, string s2, int i = 1) {
for(; !s1.empty(); s1 = mp[s1].first, ++i) {
int j = 1;
for(string s = s2; !s2.empty() && j <= 5; s = mp[s].first, ++j) {
if(s1 == s && (i < 5 || j < 5)) return false;
}
}
return true;
}
int main() {
cin >> n;
for(int i = 0; i < n; ++i) {
cin >> firstname >> lastname;
if(lastname.back() == 'n') mp[firstname] = {lastname.substr(0, lastname.length() - 4), 'm'};
else if(lastname.back() == 'r') mp[firstname] = {lastname.substr(0, lastname.length() - 7), 'f'};
else mp[firstname].second = lastname.back();
}
cin >> m;
while(m--) {
cin >> s1 >> s2 >> s3 >> s4;
if(!mp.count(s1) || !mp.count(s3)) puts("NA");
else if(mp[s1].second == mp[s3].second) puts("Whatever");
else {
if(find(s1, s3)) puts("Yes");
else puts("No");
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, k, x, ans;
bool vis[N];
vector<int> road[N];
void bfs(int x) {
queue<int> Q;
Q.push(x);
while(!Q.empty()) {
ans = Q.front();
Q.pop();
for(auto& y : road[ans]) {
Q.push(y);
}
}
cout << ans;
}
int main() {
cin >> n;
for(int i = 1; i <= n; ++i) {
cin >> k;
for(int j = 0; j < k; ++j) {
cin >> x;
road[i].push_back(x);
vis[x] = true;
}
}
for(int i = 1; i <= n; ++i) {
if(!vis[i]) {
bfs(i);
return 0;
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int n, m, k, x;
int main() {
cin >> n >> m >> k;
while(k--) {
stack<int> st;
int cnt = 1, flag = 0;
for(int i = 0; i < n; ++i) {
cin >> x;
if(x == cnt) {
++cnt;
while(!st.empty() && st.top() == cnt) {
++cnt, st.pop();
}
} else {
st.push(x);
if(st.size() > m) ++flag;
}
}
if(st.empty() && !flag) puts("YES");
else puts("NO");
}
return 0;
}