| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:请教这道题如何解决输入length=0的字符串In Reply To:请教这道题如何解决输入length=0的字符串 Posted by:xhu_li at 2008-12-14 19:14:33 > /*****************************
> 一下是我写的代码,测试了几组数组,是对的,但是总是wa,希望哪位帮我看看!!!!
> 谢谢!!
>
> 我的程序不能输入length=0的字符串,是不是这格问题??????????
>
> *****************************/
>
> #include<iostream>
> #include<cstring>
> using namespace std;
> int main()
> {
> long n;
> char str1[46],str2[46];
> cin>>n;
> long p=0;
> while(n--)
> {
> p++;
> int i,j,k=0,t=0,len1=0,len2=0;
> scanf("%s",str1); //不知道这里输入的时候是否有问题
> scanf("%s",str2);
> len1=strlen(str1);
> len2=strlen(str2);
> if(len1==0||len2==0)
> {
> if(len1>len2)
> cout<<"Case #"<<p<<": "<<len1<<endl;
> else
> cout<<"Case #"<<p<<": "<<len2<<endl;
> continue;
> }
> for(i=0;i<len1;i++)
> {
> for(j=0;j<len2;j++)
> {
> if(str1[i]==str2[j])
> {
> str2[j]='0';
> k++;
> break;
> }
> }
> if(k==len2)
> break;
> }
> t=len1+len2-2*k;
> cout<<"Case #"<<p<<": "<<t<<endl;
> }
> return 0;
> }
>
Each case will consist of two words, possibly empty,可能有空输出,用gets试下
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator