Codeforces 102263C-Check The Text【模拟】 难度:*

题意:

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 n (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 m (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
inputCopy
2
Hello World
18
CapsLock
h
CapsLock
e
l
l
Backspace
o
Space
w
o
Backspace
Backspace
w
o
r
l
d
outputCopy
Incorrect

题解:

按部就班模拟就好了,注意对比一些特殊的字符串

代码:

#include<stdio.h>
#include<string.h>
char goal[2005],now[2005],temp[2005];
char back[15]={"Backspace"},space[10]={"Space"},cap[15]={"CapsLock"};
int main()
{
	int n,m,kind=0;
	scanf("%d",&n);
	getchar();back[9]='\0';space[5]='\0';cap[8]='\0';now[0]='\0';
	gets(goal);
	scanf("%d",&m);
	while(m--)
	{
		scanf("%s",temp);
		if(strcmp(temp,back)==0)
		{
			if(strlen(now))now[strlen(now)-1]='\0';
		}
		else if(strcmp(temp,space)==0)now[strlen(now)]=' ';
		else if(strcmp(temp,cap)==0)kind=1-kind;
		else
		{
			if(kind)temp[0]+='A'-'a';
			now[strlen(now)]=temp[0];
		}
	}
	if(strcmp(now,goal)==0)printf("Correct\n");
	else printf("Incorrect\n");
}

猜你喜欢

转载自blog.csdn.net/weixin_42921101/article/details/104447920