HDU 2054 A == B ?
2014-01-25 01:13
309 查看
题目:
http://acm.hdu.edu.cn/showproblem.php?pid=2054
收获很大的一道题,一开始看到这道题笑了,做到最后差点哭了,还好有度娘。
题解:
要考虑到这种数据,00123.123000 123.123 是相等的。
所以只要对输入的数据简化即可。
用到strchr函数:
代码:
#include<stdio.h>
#include<string.h>
char a[20000],b[20000];
void simplify(char*p)
{
while(*p=='0') p++;
if(strchr(p,'.'))
{
int len=strlen(p);
char *s=p+len-1;
while(*s=='0') *(s--)='\0';
if(*s=='.') *s='\0';
}
}
int main()
{
while(~scanf("%s%s",a,b))
{
simplify(a);
simplify(b);
if(strcmp(a,b)==0)
printf("YES\n");
else printf("NO\n");
}
return 0;
}
http://acm.hdu.edu.cn/showproblem.php?pid=2054
收获很大的一道题,一开始看到这道题笑了,做到最后差点哭了,还好有度娘。
题解:
要考虑到这种数据,00123.123000 123.123 是相等的。
所以只要对输入的数据简化即可。
用到strchr函数:
原型:extern char *strchr(char *s,char c); 用法:#include <string.h> 功能:查找字符串s中首次出现字符c的位置 说明:返回首次出现c的位置的指针,如果s中不存在c则返回NULL。
代码:
#include<stdio.h>
#include<string.h>
char a[20000],b[20000];
void simplify(char*p)
{
while(*p=='0') p++;
if(strchr(p,'.'))
{
int len=strlen(p);
char *s=p+len-1;
while(*s=='0') *(s--)='\0';
if(*s=='.') *s='\0';
}
}
int main()
{
while(~scanf("%s%s",a,b))
{
simplify(a);
simplify(b);
if(strcmp(a,b)==0)
printf("YES\n");
else printf("NO\n");
}
return 0;
}
相关文章推荐
- 【ios 汇总 - UI 视图布局 】
- C argc and argv Examples to Parse Command Line Arguments
- Android多线程之AnsyncTask
- JAVA序列化和反序列化
- java中面向对象的思想
- 九种常用设计模式的应用
- 小数学解决大问题 - 信息熵(由对数函数想到)
- 网络编程学习_设计模式_半同步半异步模式
- Eclipse for php + Xdebug搭建PHP的调试环境
- 【MLF Week 7 上】Overfitting和Regularization
- 年轻有梦,勇敢去追——我眼中的软件行业趋势
- bash中的操作
- iwconfig 命令
- 在应用程序中使用Spring启动嵌入式Jetty并让Web程序共享同一个Application Context(二)
- 2014,新的一年我的计划
- uva 1467 - Installations( 贪心+暴力)
- 在应用程序中使用Spring启动嵌入式Jetty并让Web程序共享同一个Application Context(一)
- [wikioi1553]互斥的数(数学分析+散列/数学分析+二分)
- 用Eclipse编译你的ROS程序
- 文字向上无缝滚动