zoukankan      html  css  js  c++  java
  • hdu 2054 A==B?

    A == B ?

                                                                           Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

    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
    题意:给你两个数,判断是否相等。
          刚看到这个题时,觉得这也太简单了,两个数相减,判断差是否是0不就行了。于是很快写好代码,果断提交,Wrong Answer!顿时无语。后来听人说要用字符串,又写了一个代码还是WrongAnswer。原来是给的数可能是小数且可能在末尾还有无用的0,要把这些0去掉再比较。查了一些资料以后,终于把这个题搞定了,和大家分享一下我的代码:
    #include<stdio.h>
    #include<string.h>
    char *change(char *s)
    {
    	int len=strlen(s);
    	if(strchr(s,'.')!=NULL) /*如果有小数点*/
    	{
    		while(s[--len]=='0'); //去掉小数点后面的没用的0,从后往前去
          	if(s[len]=='.') /*小数点后全是0时执行此操作*/
    			len--; /*把小数点去掉*/
    		s[len+1]='\0'; /*保留有效的数*/
    	}
    	return s;
    }
    int main()
    {
    	char s1[14000],s2[14000];
    	while(~scanf("%s %s",s1,s2))
    	{
    		if(!strcmp(change(s1),change(s2))) /*字符串比较,相等返回0*/
    			printf("YES\n");
    		else
    			printf("NO\n");
    	}
    	return 0;
    }
    注意:这个题不用考虑前导0,即008这种情况不用考虑。
    strchr(s,'.')函数是判断在字符串s中是否含有小数点,如果没有就返回空指针;有的话就返回指针位置,即地址。

  • 相关阅读:
    e667. 在给定图像中创建缓冲图像
    e661. 确定图像中是否有透明像素
    e673. Getting Amount of Free Accelerated Image Memory
    e663. 在gif图像中获取透明和色彩的数量
    e662. 取的图像的色彩模型
    e675. 翻转缓冲图像
    e665. 在图像中过滤三元色
    e679. 浮雕化图像
    e669. 绘制缓冲图像
    e664. 在图像中获取子图像
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3111409.html
Copyright © 2011-2022 走看看