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; }
相关文章推荐
- 1/22 测试一(STL 模拟 贪心)C.(贪心,给出气球,输出最好成绩)Contest Balloons
- 1/22 测试一(STL 模拟 贪心)E.(贪心 通过修改字母和调整顺序使字符串成为回文串)Make Palindrome
- 比较两个字符串是否相等,相等输出MATCH,否则NOMATCH
- 汇编语言中有一种移位指令叫做循环左移(ROL),现在有个简单的任务,就是用字符串模拟这个指令的运算结果。对于一个给定的字符序列S,请你把其循环左移K位后的序列输出。例如,字符序列S=”abcXYZde
- 编写一个程序,将两个字符串s1和s2比较,如果s1 > s2,输出一个正数;s1 = s2,输出0,;s1 < s2输出一个负数。不要使用strcmp函数。
- 汇编语言中有一种移位指令叫做循环左移(ROL),现在有个简单的任务,就是用字符串模拟这个指令的运算结果。对于一个给定的字符序列S,请你把其循环左移K位后的序列输出。例如,字符序列S=”abcXYZdef”,要求输出循环左移3位后的结果,即“XYZdefabc”。是不是很简单?OK,搞定它!
- 输入两个数字,将比较结果输出到页面
- 截取字符串。输入字符串和按照多大字节进行截取,输出结果:按照字节截取的字符串。注意:汉字占两个字节,所以输入的汉字不能截取为半个汉字!!!例子:输入“我ABC爱北京”,字节输入6,结果为:“我ABC”
- 不用比较运算符实现两个整数的大小比较并输出结果
- 不用比较运算符实现两个整数的大小比较并输出结果
- 【C语言】模拟strcmp比较两个字符串
- 汇编 输入几个数子进行比较 不同条输出不同的结果 三个相同输出2 两个同输出1 不同输出0
- perl 两个字符串输出相同但是比较失败
- 习题 6.14 编一个程序,将两个字符串s1和s2比较,若s1>s2,输出一个正数;若s1=s2, 输出0;若s1<s2,输出一个负数。不要用strcmp函数。两个字符串用gets函数输入。
- LeetCode425——Add Strings(两个字符串中的数字相加(十进制或二进制),输出字符串形式的结果)
- PHP两个字符串比较(人为出错),两字符串类型和数据表面相等,但strcmp()结果不为0
- 汇编语言中有一种移位指令叫做循环左移(ROL),现在有个简单的任务,就是用字符串模拟这个指令的运算结果。对于一个给定的字符序列S,请你把其循环左移K位后的序列输出。例如,字符序列S=”abcXYZde
- [SoapUI] 比较两个不同环境下的XML Response, 从外部文件读取允许的偏差值,输出结果到文本文件
- 看结果,测试?java中的String类 字符串拆分成字符串数组 判定邮箱地址 字符串比较 参数传递?
- 比较两个字符串是否相等,相等输出MATCH,否则NOMATCH