首页 > 其他 > 详细

【字符串】Almost Identical Programs

时间:2018-09-03 00:36:46      阅读:209      评论:0      收藏:0      [点我收藏+]

题目描述

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

原文:https://www.cnblogs.com/SoulSecret/p/9575866.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!