字符串Almost Identical Programs
Posted soulsecret
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了字符串Almost Identical Programs相关的知识,希望对你有一定的参考价值。
题目描述
The programming contest named Concours de Programmation Comtemporaine Interuniversitaire (CPCI) has a judging system similar to that of ICPC; contestants have to submit correct outputs for two different inputs to be accepted as a correct solution. Each of the submissions should include the program that generated the output. A pair of submissions is judged to be a correct solution when, in addition to the correctness of the outputs, they include an identical program.
Many contestants, however, do not stop including a different version of their programs in their second submissions, after modifying a single string literal in their programs representing the input file name, attempting to process different input. The organizers of CPCI are exploring the possibility of showing a special error message for such close submissions, indicating contestants what‘s wrong with such submissions. Your task is to detect such close submissions.
输入
The input consists of at most 100 datasets, each in the following format.
s1
s2
Each of s1 and s2 is a string written in a line, with the length between 1 and 200, inclusive. They are the first and the second submitted programs respectively. A program consists of lowercase letters (a, b, ..., z), uppercase letters (A, B, ..., Z), digits (0, 1, ..., 9), double quotes ("), and semicolons (;). When double quotes occur in a program, there are always even number of them.
The end of the input is indicated by a line containing one ‘.’ (period).
输出
For each dataset, print the judge result in a line.
If the given two programs are identical, print IDENTICAL. If two programs differ with only one corresponding string literal, print CLOSE. Otherwise, print DIFFERENT. A string literal is a possibly empty sequence of characters between an odd-numbered occurrence of a double quote and the next occurrence of a double quote.
样例输入
print"hello";print123
print"hello";print123
read"B1input";solve;output;
read"B2";solve;output;
read"C1";solve;output"C1ans";
read"C2";solve;output"C2ans";
""""""""
"""42"""""
slow"program"
fast"code"
"super"fast"program"
"super"faster"program"
X""
X
I"S""CREAM"
I"CE""CREAM"
11"22"11
1"33"111
.
样例输出
IDENTICAL
CLOSE
DIFFERENT
CLOSE
DIFFERENT
DIFFERENT
DIFFERENT
CLOSE
DIFFERENT
代码如下:
1 #include <iostream>
2 #include <bits/stdc++.h>
3 using namespace std;
4 string str1,str2;
5 int cnt,pos1,pos2;
6 void judge()
7 {
8 string a,b;
9 pos1++,pos2++;
10 while(str1[pos1]!=‘"‘)
11 {
12 a+=str1[pos1];
13 pos1++;
14 }
15 while(str2[pos2]!=‘"‘)
16 {
17 b+=str2[pos2];
18 pos2++;
19 }
20 if(a!=b)
21 cnt++;
22 }
23 int main()
24 {
25 while(cin>>str1)
26 {
27 if(str1==".")
28 break;
29 cin>>str2;
30 pos1=0,pos2=0;
31 cnt=0;
32 bool flag=true;
33 for(;pos1<str1.size();pos1++,pos2++)
34 {
35 if(str1[pos1]!=‘"‘)
36 {
37 if(str1[pos1]!=str2[pos2])
38 {
39 flag=false;
40 break;
41 }
42 }
43 else
44 {
45 if(str1[pos1]!=str2[pos2])
46 {
47 flag=false;
48 break;
49 }
50 else
51 {
52 judge();
53 }
54 }
55 }
56 if(pos2!=str2.size())
57 flag=false;
58 if(!flag||cnt>=2)
59 {
60 cout << "DIFFERENT" << endl;
61 }
62 else if(cnt==1)
63 {
64 cout << "CLOSE" <<endl;
65 }
66 else if(cnt==0)
67 {
68 cout << "IDENTICAL" << endl;
69 }
70 }
71 //cout << "Hello world!" << endl;
72 return 0;
73 }
View Code
以上是关于字符串Almost Identical Programs的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #529 (Div. 3) E. Almost Regular Bracket Sequence (思维)