杭电acm 2054 ,一直wa,难道漏考虑情况了???
ProblemDescriptionGiveyoutwonumbersAandB,ifAisequaltoB,youshouldprint"YES",orprint"NO...
Problem Description
Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".
Input
each test case contains two numbers A and B.
Output
for each case, if A is equal to B, you should print "YES", or print "NO".
Sample Input
1 2
2 2
3 3
4 3
Sample Output
NO
YES
YES
NO
提交代码:
#include<iostream>
#include<string>
using namespace std;
int main()
{
char a[100000];
char b[100000];
char a2[100000];
char b2[100000];
memset(a,'\0',sizeof(a));
memset(b,'\0',sizeof(b));
memset(a2,'\0',sizeof(a2));
memset(b2,'\0',sizeof(b2));
cin>>a>>b;
int j = 0;
while(a[j]=='0') //计算前面有多少个0
{
j++;
}
int i = 0;
while(a[j]!='\0') //前面0删了
{
a2[i] = a[j];
i++;
j++;
}
i = i-1;
if(strchr(a2,'.')) //有小数点把后面0删了
{
while(a2[i]=='0')
{
a2[i] = '\0';
i--;
}
if(a2[i]=='.')a2[i]='\0'; //后面全是0把小数点删了
}//---------------------------------------------------------------------
j = 0;
while(b[j]=='0') //---------------同理
{
j++;
}
i = 0;
while(b[j]!='\0')
{
b2[i] = b[j];
i++;
j++;
}
i = i-1;
if(strchr(b2,'.'))
{
while(b2[i]=='0')
{
b2[i] = '\0';
i--;
}
if(b2[i]=='.')b2[i]='\0';
}
int c = strcmp(a2,b2); //两个字符串是否相等
if(c==0)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
} 展开
Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".
Input
each test case contains two numbers A and B.
Output
for each case, if A is equal to B, you should print "YES", or print "NO".
Sample Input
1 2
2 2
3 3
4 3
Sample Output
NO
YES
YES
NO
提交代码:
#include<iostream>
#include<string>
using namespace std;
int main()
{
char a[100000];
char b[100000];
char a2[100000];
char b2[100000];
memset(a,'\0',sizeof(a));
memset(b,'\0',sizeof(b));
memset(a2,'\0',sizeof(a2));
memset(b2,'\0',sizeof(b2));
cin>>a>>b;
int j = 0;
while(a[j]=='0') //计算前面有多少个0
{
j++;
}
int i = 0;
while(a[j]!='\0') //前面0删了
{
a2[i] = a[j];
i++;
j++;
}
i = i-1;
if(strchr(a2,'.')) //有小数点把后面0删了
{
while(a2[i]=='0')
{
a2[i] = '\0';
i--;
}
if(a2[i]=='.')a2[i]='\0'; //后面全是0把小数点删了
}//---------------------------------------------------------------------
j = 0;
while(b[j]=='0') //---------------同理
{
j++;
}
i = 0;
while(b[j]!='\0')
{
b2[i] = b[j];
i++;
j++;
}
i = i-1;
if(strchr(b2,'.'))
{
while(b2[i]=='0')
{
b2[i] = '\0';
i--;
}
if(b2[i]=='.')b2[i]='\0';
}
int c = strcmp(a2,b2); //两个字符串是否相等
if(c==0)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
} 展开
2个回答
展开全部
#include<iostream>
#include<string>
using namespace std;
int main()
{
char a[100000];
char b[100000];
char a2[100000];
char b2[100000];
memset(a,'\0',sizeof(a));
memset(b,'\0',sizeof(b));
while(cin>>a>>b){//一直读入直到文件结尾
memset(a2,'\0',sizeof(a2));
memset(b2,'\0',sizeof(b2));
int j = 0;
int flag1=0,flag2=0;//记录两个字符串的符号,要考虑正负号 +0.0 -0.0
if(a[0]=='+'){
flag1=0;
strcpy(a,a+1);
}
if(a[0]=='-'){
flag1=1;
strcpy(a,a+1);
}
if(b[0]=='+'){
flag2=0;
strcpy(b,b+1);
}
if(b[0]=='-'){
flag2=1;
strcpy(b,b+1);
}
while(a[j]=='0') //计算前面有多少个0
{
j++;
}
int i = 0;
while(a[j]!='\0') //前面0删了
{
a2[i] = a[j];
i++;
j++;
}
i = i-1;
if(strchr(a2,'.')) //有小数点把后面0删了
{
while(a2[i]=='0')
{
a2[i] = '\0';
i--;
}
if(a2[i]=='.')a2[i]='\0'; //后面全是0把小数点删了
}//---------------------------------------------------------------------
j = 0;
while(b[j]=='0') //---------------同理
{
j++;
}
i = 0;
while(b[j]!='\0')
{
b2[i] = b[j];
i++;
j++;
}
i = i-1;
if(strchr(b2,'.'))
{
while(b2[i]=='0')
{
b2[i] = '\0';
i--;
}
if(b2[i]=='.')b2[i]='\0';
}
if(strlen(a2)==0)
flag1=0;
if(strlen(b2)==0)
flag2=0;
// cout<<a2<<" "<<b2<<endl;
int c = strcmp(a2,b2); //两个字符串是否相等
if(c==0 && flag1==flag2)cout<<"YES"<<endl;// 字符串相同并且符号一样
else cout<<"NO"<<endl;
}
return 0;
}
这是修改后的可以AC的代码,欢迎交流哈,满意请采纳。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询