Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求大神帮看下哪里错了 不胜感激!

Posted by quanyibo at 2014-04-25 23:28:54 on Problem 2159
思路是把源码和译码串中每个字母出现的次数记录下来
不过记录的是在一个字符数组中
把源码的每个字母出现的次数向右平移
平移0,就是原来自己,平移1。。。一直到25;
每平移一次,和译码每个字母出现的次数比较
因为记录次数用的是字符数组,所以比较好比较
直接一个strcmp就完事了
以下是我的代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
#include<math.h>
using namespace std;
int main()
{
    char ori[105],tra[105];
    char ori1[105],tra1[105];
    while(gets(ori))
    {
        gets(tra);
        int l1=strlen(ori),l2=strlen(tra),tt;
        int i,j;
        for(j=0,i=0;i<l1;i++)
        {
            if(ori[i]>='A'&&ori[i]<='Z')
            ori1[j++]=ori[i];
        }
        ori1[j]='\0';
        for(j=0,i=0;i<l2;i++)
        {
            if(tra[i]>='A'&&tra[i]<='Z')
            tra1[j++]=tra[i];
        }
        tra1[j]='\0';
        int l11=strlen(ori1),l22=strlen(tra1);
       char t1[27],t2[27];
        memset(t1,'0',sizeof(t1));
        memset(t2,'0',sizeof(t2));
        for(i=0;i<l11;i++)
        {
            t1[ori1[i]-'A']++;
        }
        for(i=0;i<l22;i++)
        {
            t2[tra1[i]-'A']++;
        }
        t1[26]=t2[26]='\0';
        //printf("%s\n%s\n",t1,t2);
        char buffer[27];
        for(i=0;i<=25;i++)
        {
            int temp=i;
            memset(buffer,'0',sizeof(buffer));
            buffer[26]='\0';
            for(j=0;j<=25;j++)
            {
                if(temp+j>25)
                temp-=26;
                buffer[j+temp]=t1[j];
            }
           tt=0;
          // printf("%s\n%s\n",buffer,t2);
            if(strcmp(buffer,t2)==0)
            {
                tt=1;
            }
            if(tt)
            goto end;
        }
        end:if(tt)
        printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator