ACM问题 我的代码哪里错了?? http://acm.swjtu.edu.cn/JudgeOnline/showproblem?problem_id=1356

http://acm.swjtu.edu.cn/JudgeOnline/showproblem?problem_id=1356我的代码:Astringyisapermut... http://acm.swjtu.edu.cn/JudgeOnline/showproblem?problem_id=1356
我的代码:
A string y is a permutation of a string x if y can be obtained by rearranging the characters of x. Write a program which repeatedly inputs pairs of strings and decides whether the second string is a permutation of the first string.

Input

A string is the concatenation of consecutive nonempty lines of input. A pair consists of a nonempty line (containing only hyphens), followed by the first string, followed by an empty line, followed by the second string, followed by an empty line. The standard input file contains one or more pairs.

Output

for each pair of strings in the standard input file, determine whether the second string is a permutation of the first string, and output a message as shown in the sample output.

Sample Input

-----
Oh, my goodness
multiple lines!

yg doo, shOmens emlusleip
!tlin

-----
perplexed

exdrelper

Sample Output

-----
The second string is a permutation of the first
-----
The second string is not a permutation of the first

Source

#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int h1,h2,i,j;
int lettera[257],letterb[257],sign;
char s[100],a[100001],b[100001];
// fgets(buf,sizeof(s),stdin);// do not use gets()
//先把所有输入都读完,再去做进一步处理。
//读取代码:
while(gets(s)) // 如果只输入两次就运行出结果 就只gets两次就行
{
char *aBuf;
memset(a,0,sizeof(a)); // a是前面定义的数组
aBuf=a;
while(gets(aBuf))
{
if(strcmp(aBuf,"")==0)
break;
aBuf+=strlen(aBuf); //这样,所有字符都被读进了a,并且所有换行符都被去除了。
}
char *bBuf;
memset(b,0,sizeof(b)); // a是前面定义的数组
bBuf=b;
while(gets(bBuf))
{
if(strcmp(bBuf,"")==0)
break;
bBuf+=strlen(bBuf); //这样,所有字符都被读进了b,并且所有换行符都被去除了。
}
// printf("a: %s\n",a);
// printf("b: %s\n",b);
memset(lettera,0,sizeof(lettera));
memset(letterb,0,sizeof(letterb));
h1=strlen(a); h2=strlen(b);
for(i=0;i<h1;i++)
lettera[a[i]]++;
for(i=0;i<h2;i++)
letterb[b[i]]++;
sign=0;
for(i=0;i<257;i++)
{
if(lettera[i]!=letterb[i])
{
sign=1;
break;
}
}
if(sign==1)
{
cout<<"-----"<<endl;
cout<<"The second string is a not permutation of the first"<<endl;
}
else
{
cout<<"-----"<<endl;
cout<<"The second string is a permutation of the first"<<endl;
}
}
return 0;
}
展开
 我来答
logiciel
2010-12-31 · TA获得超过140个赞
知道小有建树答主
回答量:223
采纳率:0%
帮助的人:367万
展开全部
cout<<"The second string is a not permutation of the first"<<endl;
改为
cout<<"The second string is not a permutation of the first"<<endl;
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式