C - Check The Text
https://vjudge.csgrandeur.cn/problem/Gym-102263C
Roze has a special keyboard which consists only of 29 keys:
-26 alphabetic a-z keys, which prints the 26 lowercase Latin letters.
-"Space" key, which prints a single space.
-"CapsLock" key, which converts the status of the letters keys from lowercase to uppercase and vice versa. The status initially is lowercase.
-"Backspace" key, which deletes the last letter/space that was written on the screen.
If Roze presses "Backspace" and there is nothing to delete on the screen, nothing will happen.
Given the text that Roze had to print and the order of the keys she has pressed on the keyboard, check if Roze has printed the text correctly (including exactly one space between every two words).
Input
The first line contains an integer nn (1<n<2000), which is the number of the words in the text Roze has to print.
Then n strings represent the text Roze has to print separated by exactly one space.
Each string consists only of uppercase and lowercase Latin letters, and the total length of all strings less than 2000
The following line contains an integer mm (1<m<2000), which is the number of the keys Roze has pressed.
Then m lines, each line contains a string that represents the key was pressed.
It's guaranteed that the last key pressed is a letter and the first key is not a space key.
Output
Print a single line containing the result of checking.
If Roze has printed the text correctly, print "Correct". Otherwise, print "Incorrect".
Example
input
Copy
2 Hello World 18 CapsLock h CapsLock e l l Backspace o Space w o Backspace Backspace w o r l d
output
Copy
Incorrect
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
-
- int n,m,flag=1,ans=1;
- string a;
- string s;
- string v;
- scanf("%d",&n);
- getchar();//别忘了!!!
- getline(cin,a);
- scanf("%d",&m);
- getchar();//别忘了!!!
- while(m--)
- {
- getline(cin,s);
- if(s=="CapsLock")
- {
- flag++;
- }
- else if(s=="Space")
- {
- v+=" ";
- }
- else if(s=="Backspace")
- {
- if(v.size())//注意别忘了,否则一直erase会越界
- v.erase(v.size()-1,1);
- }
- else
- {
- if(flag%2==0)
- {
- v+=(s[0]-32);//注意不是s
- }
- else
- {
- v+=s[0];
- }
- }
- }
- if(a==v)
- printf("Correct");
- else
- printf("Incorrect");
- return 0;
- }