Below is a photo circulating on Weibo: “Dear classmates, in view of everyone who sometimes needs to use WIFI and afraid of delaying relatives’ learning, now set the WiFi password to the following mathematical questions: A-1; B-2; C-3; D-4; please answer the students by themselves and change every two days. Thank you for your cooperation! ~ “-The teachers are also working hard to promote student learning … This question requires you to write a program The answer to a series of questions is translated into WiFi passwords according to the corresponding relationship given on the paper. There are four options for each choice question here, and there are only one correct answer.
Enter the first line to give a positive integer n (≤ 100), and then N lines. Each row gives 4 options in the format in the number-answer. T represents the correct option and f represents an error option. Divide the space between options.
Output the WIFI password in a line.
8
A-T B-F C-F D-F
C-T B-F A-F D-F
A-F D-F C-F B-T
B-T A-F C-F D-F
B-F D-T A-F C-F
A-T C-F B-F D-F
D-T B-F C-F A-F
C-T A-F B-F D-F
13224143
- Because you want to absorb the Enter, you traverse five times instead of four times
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
char a,b;
for(int i=0;i<n;i++)
for(int j=1;j<=5;j++)
{
scanf("%c-%c\n",&a,&b);
if(b=='T')
{
int c=a-64;
printf("%d",c);
}
}
return 0;
}
- Three characters ‘A-T’ are a group
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
int main()
{
string s;
while(cin>>s)
{
if(s[2]=='T')
cout<<s[0]-'A'+1;
}
return 0;
}
- cin is the end of ’ctrl+z’, so the Enter will not be identified
- cin >> str; receiving string cannot contain space, otherwise it will divide the entire string into several sections according to the space. If you want to enter a string with a space, use getline ().