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
pqpqpqpq

Output
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
pqpqpqpq

Output
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;
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值