[NOIP模拟]抄代码

样例输入:

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

题目分析:
考场总结: 考试的时候没有认真读题,结果错误的以为字母就是随便变幻,结果是要求一次操作的话所有相同的字母都要同时变。
分析:
比较简单,直接上题解:
C 君抄了 J 君的代码当且仅当以下条件被满足:
1. 两个代码的长度相等
2. 两个代码所有非字母位置的字符对应相等
3. 考虑 J 君代码中一个字母 x 出现的所有位置,在 C 君的代码中,这些位置的字母须相等

PS:其实这道题的题面理解有一定问题,按照真正的意思,上面的判断是不足的,但是标算就这样,应该是出题人的意思表达有一点问题。
附代码:

                     #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;//对应条件1
    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']!=0)
            {
                if(num[s[i]-'a']!=st[i]-'a') return false;//对应条件3   
            }
            else num[s[i]-'a']=st[i]-'a';
        }
        else if(s[i]!=st[i]) return false;//对应条件2
    return true;
}

int main()
{
    //freopen("copycat.in","r",stdin);
    //freopen("copycat2.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;
}
发布了99 篇原创文章 · 获赞 8 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qianguch/article/details/78357809