您的位置:首页 > 其它

1/22 测试一(STL 模拟 贪心)B.(模拟 比较两个字符串,输出比较结果) Online Judge

2018-01-22 23:26 369 查看

1/22 测试一(STL 模拟 贪心)

B.(模拟 比较两个字符串,输出比较结果) Online Judge

Ignatius is building an Online Judge, now he has worked out all the problems except the Judge System. The system has to read data from correct output file and user’s result file, then the system compare the two files. If the two files are absolutly same, then the Judge System return “Accepted”, else if the only differences between the two files are spaces(’ ‘), tabs(‘\t’), or enters(‘\n’), the Judge System should return “Presentation Error”, else the system will return “Wrong Answer”.

Given the data of correct output file and the data of user’s result file, your task is to determine which result the Judge System will return.

Input

The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.

Each test case has two parts, the data of correct output file and the data of the user’s result file. Both of them are starts with a single line contains a string “START” and end with a single line contains a string “END”, these two strings are not the data. In other words, the data is between the two strings. The data will at most 5000 characters.

Output

For each test cases, you should output the the result Judge System should return.

Sample Input

4

START

1 + 2 = 3

END

START

1+2=3

END

START

1 + 2 = 3

END

START

1 + 2 = 3

END

START

1 + 2 = 3

END

START

1 + 2 = 4

END

START

1 + 2 = 3

END

START

1 + 2 = 3

END

Sample Output

Presentation Error

Presentation Error

Wrong Answer

Presentation Error

题意:

给出标准字符串和用户输入的字符串,比较二者结果,若相同则输出“Accepted”, 若二者只是相差 ’ ‘, ’ \n ‘, ’ \t ‘,那么就输出“Presentation Error” ,否则输出“Wrong Answer”。

思路:

对于标准字符串和用户输入的字符串都分别用两个数组储存,其中一个保存原型,另一个将所有的 ’ ‘, ’ \n ‘, ’ \t ‘处理后的标准形式储存起来,再进行比较。

这里要注意对‘\n’的处理,因为gets函数不能读取‘\n’,所以每次使用gets函数读取一行字符后就要自动加一个’\n’。

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <set>
#define MAXN 5005

using namespace std;

int main()
{
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
char bz[MAXN], b[MAXN];
if(s == "START")
{
int i = 0, j = 0;
char str[MAXN];
while(gets(str))
{
int len  = strlen(str);
if(strcmp(str, "END") == 0)
break;
for(int k = 0; k < len; k++)
{
bz[i++] = str[k];
if(str[k] != ' ' && str[k] != '\n' && str[k] != '\t')
b[j++] = str[k];
}
bz[i++] = '\n';
}
bz[i] = '\0';
b[j] = '\0';
}
cin>>s;
char us[MAXN], u[MAXN];
if(s == "START")
{
int i = 0, j = 0;
char str[MAXN];
while(gets(str))
{
int len  = strlen(str);
if(strcmp(str, "END") == 0)
break;
for(int k = 0; k < len; k++)
{
us[i++] = str[k];
if(str[k] != ' ' && str[k] != '\n' && str[k] != '\t')
u[j++] = str[k];
}
us[i++] = '\n';
}
us[i] = '\0';
u[j] = '\0';
}
//        cout<<"#bz#"<<bz<<'#'<<endl;
//        cout<<"#b#"<<b<<'#'<<endl;
//        cout<<"#us#"<<us<<'#'<<endl;
//        cout<<"#u#"<<u<<'#'<<endl;
if(strcmp(bz, us) == 0)
cout<<"Accepted"<<endl;
else if(strcmp(b, u) == 0)
cout<<"Presentation Error"<<endl;
else
cout<<"Wrong Answer"<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐