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 ...
随机推荐
- GPS
百度百科 http://baike.baidu.com/link?url=Kl6eLdP-fveCsHt1wHF8TVuOR9wkT2K3qFnWy36PcaYaB1hdgOS_cnTEB0jIg ...
- Cleaning Shifts(区间覆盖)
/* http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?pid=1019&ojid=1&cid=10 题目: 给定一个时 ...
- C++ 路径中\\与/
windows默认使用\\ linux默认使用/ 可以都用/
- PHP中统计目录中文件以及目录中目录的大小
<?php #循环遍历目录中所有的文件,并统计目录和文件的大小 $dirName="phpMyAdmin"; $dir=opendir($dirName); #返回一 ...
- Jupyter Notebook 对LaTeX 的支持
Jupyter的Markdown模式比我原来想想的更加强大:它支持LaTeX! 支持的特性不多,应该能满足一般的需求了.
- 根据IP地址获取IP的详细信息
<?php header('Content-Type:text/html; charset=utf-8'); function ip_data() { $ip = GetIP(); $url = ...
- oracle 的变量的定义和赋值
第一种 :先定义后赋值 代码 : declare V_AgeingType varchar2(500); begin V_AgeingType :='111'; end 第二种 ...
- HDU3480
题意:给你n个数,然后让你分成m个集合,每个集合有一个值(最大值减最小值,然后平方),求整个集合的可能最小值. 思路:因为每个集合里的值只和最大和最小值有关,所以很容易想到先排序,然后用DP可求得解, ...
- 使用WMI来控制Windows目录 和windows共享机制
1.使用WMI来控制Windows目录 本文主要介绍如何使用WMI来查询目录是否存在.文件是否存在.如何建立目录.删除目录,删除文件.如何利用命令行拷贝文件,如何利用WMI拷贝文件 using Sys ...
- AutoLayout适配
http://www.raywenderlich.com/113768/adaptive-layout-tutorial-in-ios-9-getting-started iOS布局和屏幕适配的一点总 ...