HDU-2054 A==B?
#include<stdio.h>
#include<string.h>
char n[100000], m[100000];
int main()
{
int i, j, len_n, len_m, flag, len_last, len_late,doc, q, p, count, start;
char ch;
while(1)
{
memset(n, 0, sizeof(n));
memset(m, 0, sizeof(m));
flag = i = j = doc = count = start = 0;
while(1)
{
if(scanf("%c", &ch) == EOF) return 0;
if(ch == '\n' && start == 1) break;
else if(ch != ' ' && ch != '\n' && flag == 0)
{
n[i++] = ch;
}
else if(ch == ' ' || ch == '\n')
{
flag = 1;
start = 1;
}
else m[j++] = ch;
}
len_n = strlen(n);
len_m = strlen(m);
if((n[0] == '-' && m[0] != '-') || (n[0] != '-' && m[0] == '-'))
{
printf("NO\n");
continue;
}
for(i = n[0] != '-'? 0:1; i<len_n && n[i] - '0'== 0; i++);
for(j = m[0] != '-'? 0:1; j<len_m && m[j] - '0'== 0; j++);
len_n -= i;
len_m -= j;
len_last = len_n < len_m? len_n:len_m;
len_late = len_n + len_m - len_last;
{
for(; count < len_last; i++, j++, count++)
if(n[i] - '0' != m[j] - '0') break;
else if(n[i] == '.') doc = 1;
if(count >= len_late)
{
printf("YES\n");
}
else
{
if(len_n > len_m)
{
if(doc != 1 && n[i] != '.') printf("NO\n");
else
{
for(i = n[i] == '.'? i+1: i; i<strlen(n); i++)
if(n[i] - '0' != 0 ) break;
if(i>=len_n) printf("YES\n");
else printf("NO\n");
}
}
else if(len_n < len_m)
{
if(doc != 1 && m[j] != '.') printf("NO\n");
else
{
for(j = m[j] == '.'? j+1: j; j<strlen(m); j++)
if(m[j] - '0' != 0 ) break;
if(j>=len_m) printf("YES\n");
else printf("NO\n");
}
}
else if(len_n == len_m) printf("NO\n");
}
}
}
return 0;
}
1.考虑数字前面的0
2.考虑小数点后的0
3.考虑大数字
HDU-2054 A==B?的更多相关文章
- HDU 2054 A == B ?(找小数点)
题目链接:pid=2054" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=2054 Prob ...
- hdu 2054
Ps:WA了无数次,,简直成了心病..今天终于AC了..先取整数部分,去零,判断位数相等否,再比较.如果相等,再取小数部分,去零,比较,输出....好烦... 代码; #include "s ...
- hdu 2054 A == B ? (java)
问题: 考虑问题不周到.没有考虑到可能是小数并且存在 1.0=1.01=1的情况. 本题使用了BigDecimal类,此类适用于高精度的数此时攻克了小数和01=1的问题, 该类比較方式中n.equal ...
- HDU 2054 又见GCD
又见GCD Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- HDU 2054 A==B? 大数
Problem Description Give you two numbers A and B, if A is equal to B, you should print "YES&quo ...
- JAVA大数几算--HDU 2054 A == B ?
Problem Description Give you two numbers A and B, if A is equal to B, you should print "YES&quo ...
- HDU——PKU题目分类
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...
- [转] HDU 题目分类
转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008 ...
- HDU ACM 题目分类
模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
随机推荐
- wordpress 404 error on all pages!
You have to enable mod_rewrite in apache itself or you won't be able to have permalinks the way you ...
- CodeForces 221(div 2)
A 无trick水题... /* * Author: Plumrain * Created Time: 2013-12-24 22:26 * File Name: B.cpp */ #include ...
- hdu 4619 二分图最大匹配 ——最大独立集
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4619 #include <cstdio> #include <cmath> # ...
- 二次战CPP链表
Felling By Ruiy: Pre-learnning link list knowloages 熟悉 指针相关操作应用+结构体数据类型应用,且能简单融合使用,堆内存(内存泄露)->类似于 ...
- 怎么调试EXC_BAD_ACCESS错误
当你遇到了一个EXC_BAD_ACCESS错误,我通常会给开发者几个建议: 1.在可执行选项中设置NSZombieEnabled参数,这有时会帮缩小问题的范围: 2.运行apple的内存检测工具,如 ...
- 使用MyEclipse实现简单的Servlet程序
1. 创建一个继承于GenericServlet的类 3. 重写Server方法 package cn.school; import java.io.IOException; import javax ...
- readlink
readlink命令 标签: ubuntulinux工具file 2012-03-15 14:06 3674人阅读 评论(1) 收藏 举报 分类: linux系统(184) C语言(92) re ...
- Intellij 快捷键大全
Intellij IDEA的快捷键非常好用,能大大提高我们的开发速度.这里列举了一些常用的快捷键. 快速查找: Ctrl+N 查找类 Ctrl+R 替换当前窗口的文本 Ctrl+F 当前代码中查 ...
- 11th day
今天MySQL数据库的基本知识就学完了,明天开始做小项目什么的,有点小激动啊... <?php // 定义$sql语句执行函数 function my_query($sql){ $result ...
- 缓存的概念(反向代理、CDN)
缓存在我们的日常开发中随处可见,理解缓存的概念,本质就是就近处理,比如很多热点数据,访问量很多,我们需要使用,就可以把它 缓存起来,然后下次访问就不用再去数据库的去查询了,而是直接使用缓存,现在说说大 ...