HDU 5059 Help him(细节)

HDU 5059 Help him

题目链接

直接用字符串去比较即可,先判断原数字正确不正确,然后写一个判断函数,注意细节,然后注意判掉空串情况

代码:

#include <cstdio>
#include <cstring>

const int N = 105;
char n[N], a[N], b[N];

bool judge(char *str) {
	int len = strlen(str);
	if (len == 0) return false;
	int s = 0;
	if (str[s] == '-') {
		if (len == 1) return false;
		s++;
	}
	if (len != 1 && str[s] == '0') return false;
	for (int i = s; i < len; i++) {
		if (str[i] < '0' || str[i] > '9')
			return false;
	}
	return true;
}

bool big(char *a, char *b) {
	if (a[0] == '-' && b[0] != '-') return false;
	if (a[0] != '-' && b[0] == '-') return true;
	int i = 0, j = 0;
	int lena = strlen(a), lenb = strlen(b);
	bool flag = true;
	if (a[i] == '-' && b[j] == '-') {
		i++; j++;
		flag = false;
	}
	if (lena > lenb) return flag;
	if (lena < lenb) return !flag;
	while (i < lena && j < lenb) {
		if (a[i] > b[j]) return flag;
		else if (a[i] < b[j]) return !flag;
		i++; j++;
	}
	return true;
}

bool solve() {
	if (!judge(n)) return false;
	if (big(n, a) && big(b, n)) return true;
	return false;
}

int main() {
	while (gets(n) != NULL) {
		scanf("%s%s%*c", a, b);
		while (!judge(a) || !judge(b));
		printf("%s\n", solve() ? "YES" : "NO");
	}
	return 0;
}
时间: 2024-12-22 10:29:03

HDU 5059 Help him(细节)的相关文章

hdu 5059

/*  * @brief hdu 5059  * @file 5059.c  * @author xiyan  * @CreatedTime 2014/11/12  * @LastChanged 2014/11/12  * @note  *      type: string convert  *  *  */ #include <stdio.h> #include <string.h> #define MAXN 110 char s[MAXN], t[MAXN]; int a, 

BestCoder12 1002.Help him(hdu 5059) 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5059 题目意思:就是输入一行不多于 100 的字符串(除了'\n' 和 '\r' 的任意字符),问是否是合法的整数,如果是的话问是否在[a, b] 范围内,是则输出 YES,否则输出 NO 合法的整数:(1)非负整数:只有数字,没有前导0 (2)负数:负号后面只能跟着数字,负号前没有任何字符 首先这条题感觉不是出得太好,不过都是硬着头皮学人家做啦.反正一些很变态的数据可能还是过不了,但却AC的. 模

HDU 5059 Help him(简单模拟题)

http://acm.hdu.edu.cn/showproblem.php?pid=5059 题目大意: 给定一个字符串,如果这个字符串是一个整数,并且这个整数在[a,b]的范围之内(包括a,b),那就输出YES,其它的都是NO. 这个字符串是整数的条件: 1.如果它是正整数,它只包含前导不是0的数(这个数前面没有零). 2.如果它是负整数,只包含一个'-'符号,任然没有前导0. 3.除此之外都不是非法的 解题思路: http://bestcoder.hdu.edu.cn/ 这里有 要注意: 0

HDU 5059 Help him (模拟)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5059 Problem Description As you know, when you want to hack someone's program, you must submit your test data. However sometimes you will submit invalid data, so we need a data checker to check your data

hdu 5059 Help him

Help him Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 480    Accepted Submission(s): 119 Problem Description As you know, when you want to hack someone's program, you must submit your test d

hdu 5059(模拟)

Help him Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2500    Accepted Submission(s): 518 Problem Description As you know, when you want to hack someone's program, you must submit your test d

HDU 5186 zhx&#39;s submissions 模拟,细节 难度:1

http://acm.hdu.edu.cn/showproblem.php?pid=5186 题意是分别对每一位做b进制加法,但是不要进位 模拟,注意:1 去掉前置0 2 当结果为0时输出0,而不是全部去掉 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn=101; const int maxm=201; int n,b; char

HDU 2612 -Find a way (注意细节的BFS)

题目链接:Find a Way 题目不难,前几天做,当时准备写双向BFS的,后来处理细节上出了点问题,赶上点事搁置了,今天晚上重写的,没用双向,用了两次BFS搜索,和双向BFS 道理差不多,只是这题有个小坑,需要注意 1.Y不能经过M,M不能经过Y,也就是说有Y和M的格子,可以默认为是墙 2.必须是Y和M都能到达的KFC才行,只是其中一个到达不行 例如下列数据:答案既不是22 也不是 88 而是110,左下角的KFC满座条件 5 5 Y..#@ ...M. ....# ..... @.... 小

hdu 4738 无向图缩点断桥 // 细节坑题

Caocao's Bridges 题意:给个无向图,求出边权最小的桥. 一看,直接缩点,若无桥,输出-1,有桥,遍历下边,更新最小..分分钟搞定,以为IA的..一交wa... 坑点:1:若原图不连通,则无须派人去!输出0!: 2:若桥的权是0,则还有派一个人把炸弹拿去,输出1! 3:有重边.(按多条边算). 哎!记住这个教训!以后做题 1:考虑边界或者特殊数据!(边权为0!n==1等) 2:考虑原图连通性!(这次考虑了原图就强连通..没有考虑根本不连通!) 3:重边.这题的重边是按重边算(不是一