2017.10.26 T1 2010
样例数据
输入
5
int x;
int y;
double a;
double aa;
float 1
float 2
string s;
double d;
print thisismycode;
float tooooooooooo;
输出
1
0
0
1
1
分析:这真是一道一波三折的题。考场上看到这道题,哇,扫一遍就可以的暴力诶,秒掉(其实没有“秒掉”,我对字符串不太熟,还是很小心的)。考完之后,吃饭的时候讨论到这道题,高老师道出了题面的坑,“每一次操作”,也就意味着每次操作只能改一种字母,而我的理解是一次性所有的字母都改成对应的字母。
举个例子:
abcdefghijklmnopqrstuvwxyz
zyxwvutsrqponmlkjihgfedcba
以我的理解,每种字母都能唯一对应另一种字母,所以是抄袭的。但是,按题面的意思,一次只能改一种字母,比如,先把a改成了z,现在想把z改成a时就会把之前a改成的字母z给改回去,所以抄袭是做不到的。
听完这种解释我真是心灰意冷,但是拿到题解的时候,我又欣喜地发现题解的意思和我的理解是一致的(看来出题人自己出题出锅了)。之后看到成绩发现我只有60……然后发现我的程序有bug,把自己绕进去了……以后分情况要考虑完整,如果想到了原串长度大于抄袭长度的话应该立即想到抄袭长度大于原串(我就是漏了)。
代码
不要学我这么一个一个比较,太多判断会把自己绕进去(不止一次了orz)
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<iomanip>
#include<queue>
#include<set>
using namespace std;
int getint()
{
int sum=0,f=1;
char ch;
for(ch=getchar();!isdigit(ch)&&ch!='-';ch=getchar());
if(ch=='-')
{
f=-1;
ch=getchar();
}
for(;isdigit(ch);ch=getchar())
sum=(sum<<3)+(sum<<1)+ch-48;
return sum*f;
}
int T,cnt,cnt2;
char j[1010],mtch[30];
bool bj;
int main()
{
freopen("copycat.in","r",stdin);
freopen("copycat.out","w",stdout);
char ch;
T=getint();
while(T--)
{
memset(mtch,0,sizeof(mtch));
cnt=0,cnt2=0,bj=0;
ch=getchar();
while(ch!='\n')
{
cnt++;
j[cnt]=ch;
ch=getchar();
}
ch=getchar();
while(ch!='\n'&&ch!=EOF)
{
cnt2++;
if(bj==0)
{
if(cnt2>cnt)
{
cout<<0<<'\n';
bj=1;
}
else if(((ch<'a'||ch>'z')&&(j[cnt2]<'a'||j[cnt2]>'z')&&ch!=j[cnt2])||((ch>='a'&&ch<='z')&&(j[cnt2]<'a'||j[cnt2]>'z'))||((ch<'a'||ch>'z')&&(j[cnt2]>='a'&&j[cnt2]<='z')))
{
cout<<0<<'\n';
bj=1;
}
else
{
if(ch>='a'&&ch<='z')
if(!mtch[j[cnt2]-'a'])
mtch[j[cnt2]-'a']=ch;
else
if(ch!=mtch[j[cnt2]-'a'])
{
cout<<0<<'\n';
bj=1;
}
}
ch=getchar();
}
else
ch=getchar();
}
if(bj==0)
{
if(cnt2<cnt)//抄袭串本身就小于原串的话在上面是判不了的
cout<<0<<'\n';
else
cout<<1<<'\n';
}
}
return 0;
}
可以学学这种整体处理法,多么简单诶,我为什么偏偏要写那么绕呢orz
#include<iostream>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cstdio>
#include<ctime>
#include<cmath>
#include<cctype>
#include<iomanip>
#include<algorithm>
using namespace std;
int t,lens,lent,num[100];
char s[2000],st[2000];
int readint()
{
char ch;int i=0,f=1;
for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
if(ch=='-') {ch=getchar();f=-1;}
for(;ch>='0'&&ch<='9';ch=getchar()) i=(i<<3)+(i<<1)+ch-'0';
return i*f;
}
bool check()
{
if(lens!=lent) return false;//长度不同直接false
for(int i=1;i<=lens;i++)
if(s[i]>='a'&&s[i]<='z'&&st[i]>='a'&&st[i]<='z')//字母情况
{
if(num[s[i]-'a'])//如果前面已经记录了这种字母对应的字母
{
if(num[s[i]-'a']!=st[i]-'a')
return false;
}
else
num[s[i]-'a']=st[i]-'a';
}
else if(s[i]!=st[i]) return false;//非字母情况
return true;
}
int main()
{
freopen("copycat.in","r",stdin);
freopen("copycat.out","w",stdout);
t=readint();
while(t--)
{
memset(num,0,sizeof(num));
lens=0;lent=0;
do {s[++lens]=getchar();}
while(s[lens]!='\n');//把两个串都先读完
do {st[++lent]=getchar();}
while(st[lent]!='\n'&&st[lent]!=EOF);
lens--;lent--;
if(check()==true) printf("1\n");
else printf("0\n");
}
return 0;
}
本题结。