杭电2054 A==B?

来源:百度知道 编辑:UC知道 时间:2024/05/16 08:21:35
题目 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<stdio.h>
int main()
{
int i,j,leap,pa,pb,ka,kb;
char a[100],b[100];
while(scanf("%s%s",a,b)!=EOF)
{
ka=0;kb=0;
leap=0;
pa=0;pb=0;
while(a[pa]=='0')
pa++;
while(b[pb]=='0')
pb++;
if(a[pa]=='\0'&&b[pb]=='\0')
{
printf("YES\n");
continue;
}
for(i=pa,j=pb;a[i]||b[j];i++,j++)
{
if(a[i]=='.')
ka=1;
if(b[j]==&

你判断字符串是否相等
用 int strcmp(const char *, const char *);

相等时返回 0;
前大 返回 1
前小 返回 -1

你试试下面的测试数据
0.001 0.0010000000000000000000000

你的思路不够清晰,题目本身就只有一种特殊情况,那就是两个数中,有一个有后缀零,即零多余,你把多余零去掉后用strcmp比较一下即可.

你的代码有一个明显的错误
while(b[++j])
{
if(b[j]=='0')
leap=1;
else
leap=0;
j++;
}
j加了两次,而且当b[j]!='0'时有leap=0,此时就可以知道结果是NO了,不退出继续执行的话,碰到b[j]=='0'的时,leap又变为1,结果也变了

其他还有一些错误,建议你重新写一下

你不用strcmp的话,建议leap初始化为1,在排除特殊情况后,若a[i]!=b[i],leap变0,直接退出。

你想在ACM方面能有很大提高到话,建议思路理清后再写,不然即使你测了多少数据并且结果都正确,你还是不会有多大信心保证一定会AC的