C题解1076 Wifi密码 (15 分)
原题
https://pintia.cn/problem-sets/994805260223102976/problems/994805262622244864
代码
#include
int main(void)
{
int num;
scanf("%d", &num);
getchar(); //读取一个换行符
char result[101];
for (int i = 0; i < num; i++)
{
for (int j = 0; j < 4; j++)
{
char options, answer;
scanf("%c-%c", &options, &answer);
getchar(); //读取一个空格符
if (answer == 'T')
{
switch (options)
{
case 'A':
result[i] = '1';
break;
case 'B':
result[i] = '2';
break;
case 'C':
result[i] = '3';
break;
case 'D':
result[i] = '4';
break;
default:
break;
}
}
}
}
printf("%s", result);
return 0;
}
参照别人的c++
自己在本地复制粘贴样例整块输入,没能显示完全。但提交测试可以通过的。
#include
using namespace std;
int main() {
string s;
while (cin >> s) //很随性的输入循环
if(s.size() == 3 && s[2] == 'T') cout << s[0]-'A'+1;
return 0;
}