Codeforces Round 993B. Normal Problem
如何查找这道题,只需要打开一个问题,然后拷贝链接地址,修改里面的数字为2044就可以了。
例如:https://codeforces.com/contest/2044/problem/B
的确有时候不知道怎么找,我也是最近发现的。
/*
A string consisting of only characters p,q,and w is painted on a glass window of a store.
Ship walks past the store,standing directly in front of the glass window,
and observes string A.
Ship then heads insert the store,looks directly at the same glass window,
and observes string b.
Ship gives you string A,your job is to find and output B.
Input
The first line contains an integer t(1≤t≤100) — the number of test cases.
The only line of each test case contains a string a(1≤ | a | ≤100)
— the string Ship observes from outside the store.
It is guaranteed that a only contains characters 'p', 'q', and 'w'.
Output
For each test case, output string b, the string Ship observes from inside the store,
on a new line.
Example
Input
5
qwq
ppppp
pppwwwqqq
wqpqwpqwwqp
pqpqpqpq
Output
pwp
qqqqq
pppwwwqqq
qpwwpqwpqpw
pqpqpqpq
*/
/*
根据题意,从窗户外面看到一个字符串,然后需要你给出窗户里面的字符串是什么?
字符的内容是q,p,w三个字母组成。
根据例子,分析如下,在窗户里面,就是倒着,即从后往前,或者说从右边到前面。
这样,p就等于q,而q就等于p,而w不改变。仅此规则。
Note:1 from right to left. 2 p=q,or q=p, w is not change
由于是国外网站,我在程序里面尽量用英文。
*/
思路很简单,得到输入,然后立刻倒着输出,并且遇到q就改写为p,遇到p就改写为q,而w不改变,
非常容易。我用简单的方法:一边输入一边输出。这种情况可以被AC, 也可以集体输出,需要使用vector<string> list来存储输出结果,最后显示即可。
/*
A string consisting of only characters p,q,and w is painted on a glass window of a store.
Ship walks past the store,standing directly in front of the glass window,
and observes string A.
Ship then heads insert the store,looks directly at the same glass window,
and observes string b.
Ship gives you string A,your job is to find and output B.Input
The first line contains an integer t(1≤t≤100) — the number of test cases.
The only line of each test case contains a string a(1≤ | a | ≤100)
— the string Ship observes from outside the store.
It is guaranteed that a only contains characters 'p', 'q', and 'w'.Output
For each test case, output string b, the string Ship observes from inside the store,
on a new line.
Example
Input
5
qwq
ppppp
pppwwwqqq
wqpqwpqwwqp
pqpqpqpqOutput
pwp
qqqqq
pppwwwqqq
qpwwpqwpqpw
pqpqpqpq
*//*
Note:1 from right to left. 2 p=q,or q=p, w is not change
*/
#include <iostream>
#include <string>
using namespace std;
int main()
{int t = 0;string str1 = "",str2="";const char c_q = 'q';const char c_p = 'p';cin >> t;getchar();while (t--){getline(cin, str1);for (int i = str1.length()-1; i >= 0; i--){if (str1[i] == c_q){str2 += c_p;}else if (str1[i] == c_p){str2 += c_q;}else{str2 += str1[i];}}cout << str2<<endl;str2.clear();}return 0;
}
最后一次输出,用vector<string> list存放输出
/*
A string consisting of only characters p,q,and w is painted on a glass window of a store.
Ship walks past the store,standing directly in front of the glass window,
and observes string A.
Ship then heads insert the store,looks directly at the same glass window,
and observes string b.
Ship gives you string A,your job is to find and output B.Input
The first line contains an integer t(1≤t≤100) — the number of test cases.
The only line of each test case contains a string a(1≤ | a | ≤100)
— the string Ship observes from outside the store.
It is guaranteed that a only contains characters 'p', 'q', and 'w'.Output
For each test case, output string b, the string Ship observes from inside the store,
on a new line.
Example
Input
5
qwq
ppppp
pppwwwqqq
wqpqwpqwwqp
pqpqpqpqOutput
pwp
qqqqq
pppwwwqqq
qpwwpqwpqpw
pqpqpqpq
*//*
Note:1 from right to left. 2 p=q,or q=p, w is not change
*/
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{int t = 0;string str1 = "",str2="";vector<string> rslist;const char c_q = 'q';const char c_p = 'p';cin >> t;getchar();while (t--){getline(cin, str1);for (int i = str1.length()-1; i >= 0; i--){if (str1[i] == c_q){str2 += c_p;}else if (str1[i] == c_p){str2 += c_q;}else{str2 += str1[i];}}//cout << str2<<endl;rslist.push_back(str2);str2.clear();}for (int i = 0; i < rslist.size();i++){cout << rslist[i] << endl;}return 0;
}