杭电acm2054
解决时间 2021-01-22 23:41
- 提问者网友:疯孩纸
- 2021-01-22 11:07
#include
void main()
{int A,B;
while(scanf("%d %d",&A,&B)!=EOF)
{if(A==B) printf("YES");
else printf("NO");
}
}
A == B ?
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 21632 Accepted Submission(s): 3087
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
Output Limit Exceeded。。。错在哪?思路错了?帮帮忙吧。。
最佳答案
- 五星知识达人网友:蓝房子
- 2021-01-22 11:32
首先你连换行都没输出,还有你用系统的整型是肯定不行的,因为题目没说数据究竟是多大,而且题目没说一定要是整型,事实上,此题会要求你能处理小数的比较。
这样就只能是定义A和B为字符串数组了,函数用字符串比较得了,不过你不要想只用strcmp(A,B)就行了,因为此题数据恶心,要求你能比较像这样的数据:0.000==0 0.00001000==0.00001 1.000==1 000002==2,够恶心的数据了。考虑完这些情况,就慢慢写函数处理得了,不难。
附通过程序。
#include
#include
int isdec(const char *p)
{
int i,len=strlen(p);
for(i=0;i
if(*p=='.') return 1;
p++;
}
return 0;
}
void del0(char *p)
{
int len = strlen(p);
char *last = p+len-1;
while(*last =='0') *last-- = '\0';
if(*last == '.') *last = '\0';
}
int main()
{
char a[200000],b[200000],*x,*y;
while(scanf("%s%s",a,b)!=EOF){
x = a; y = b;
while(*x == '0') x ++;
while(*y == '0') y ++;
if(isdec(a)) del0(a);
if(isdec(b)) del0(b);
puts(strcmp(x,y)?"NO":"YES");
}
return 0;
}
如果还有什么不明白的话,可以M我或者留言。
全部回答
- 1楼网友:冷風如刀
- 2021-01-22 12:32
只能说你考虑多了,其实只要考虑
1.00100 1.001
1.0000 1
就行了,去掉后面的0;
#include
#include
#include
using namespace std;
char a[50000],b[50000];
void run(char *a){
int flg=0;
for(;*a;a++)
if(*a=='.') flg=1;
if(flg){
for(a--;*a=='0';a--);
if(*a=='.') *a=0;
*(a+1)=0;
}
}
int main(){
while(cin>>a>>b){
run(a),run(b),puts(strcmp(a,b)?"no":"yes");
}
return 0;
}代码已ac
我要举报
大家都在看
推荐资讯