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 data. However sometimes you will submit invalid data, so we need a
data checker to check your data. Now small W has prepared a problem for
BC, but he is too busy to write the data checker. Please help him to
write a data check which judges whether the input is an integer ranged
from a to b (inclusive).
Note: a string represents a valid integer when it follows below rules.
1. When it represents a non-negative integer, it contains only digits without leading zeros.
2. When it represents a negative integer, it contains exact one
negative sign ('-') followed by digits without leading zeros and there
are no characters before '-'.
3. Otherwise it is not a valid integer.
 
Input
Multi
test cases (about 100), every case occupies two lines, the first line
contain a string which represents the input string, then second line
contains a and b separated by space. Process to the end of file.

Length of string is no more than 100.
The string may contain any characters other than '\n','\r'.
-1000000000≤a≤b≤1000000000

 
Output
For
each case output "YES" (without quote) when the string is an integer
ranged from a to b, otherwise output "NO" (without quote).
 
Sample Input
10
-100 100
1a0
-100 100
 
Sample Output
YES
NO
 
Source
 
题意:判断一个字符串是否符合要求:
假设为正数,不能有前导0
假设为负数,最前面有 - 号,整数部分不能有前导0
这个串必须在 [a,b]之间
这个题坑的地方:判断 0 ,一定开longlong,我就被long long 坑死了。然后还有一点就是gets()读入。
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std; char str[];
int main()
{
while(gets(str)){
long long a,b;
scanf("%lld%lld",&a,&b);
getchar();
if(strcmp(str,"")==){
if(a<=&&b>=) printf("YES\n");
else printf("NO\n");
continue;
}
int len = strlen(str);
if(len>){
printf("NO\n");
continue;
}
int s = ;
bool flag = false,is_nag = false;
if(str[]=='-') {
s++;
is_nag = true;
}
long long sum = ;
if(str[s]==''||!isdigit(str[s])) flag = true;
for(int i=s;i<len&&!flag;i++){
if(isdigit(str[i])){
sum = sum* + str[i]-'';
}else{
flag = true;
}
}
if(flag){
printf("NO\n");
}else{
if(is_nag) sum = -sum;
if(sum>=a&&sum<=b){
printf("YES\n");
}else{
printf("NO\n");
}
}
}
return ;
}

hdu 5059(模拟)的更多相关文章

  1. HDU 5059 Help him(细节)

    HDU 5059 Help him 题目链接 直接用字符串去比較就可以,先推断原数字正确不对,然后写一个推断函数,注意细节,然后注意判掉空串情况 代码: #include <cstdio> ...

  2. HDU 5059 Help him(简单模拟题)

    http://acm.hdu.edu.cn/showproblem.php?pid=5059 题目大意: 给定一个字符串,如果这个字符串是一个整数,并且这个整数在[a,b]的范围之内(包括a,b),那 ...

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5059 题目意思:就是输入一行不多于 100 的字符串(除了'\n' 和 '\r' 的任意字符),问是否 ...

  4. hdu 4891 模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...

  5. hdu 5059 简单字符串处理

    http://acm.hdu.edu.cn/showproblem.php?pid=5059 确定输入的数是否在(a,b)内 简单字符串处理 #include <cstdio> #incl ...

  6. hdu 5012 模拟+bfs

    http://acm.hdu.edu.cn/showproblem.php?pid=5012 模拟出骰子四种反转方式,bfs,最多不会走超过6步 #include <cstdio> #in ...

  7. HDU 5059 Harry And Biological Teacher

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5069 题意:给出n个串,m个询问,每个询问(u,v),求u的一个最长后缀是v的前缀. 思路:离线.将关于u ...

  8. hdu 4669 模拟

    思路: 主要就是模拟这些操作,用链表果断超时.改用堆栈模拟就过了 #include<map> #include<set> #include<stack> #incl ...

  9. 2013杭州网络赛C题HDU 4640(模拟)

    The Donkey of Gui Zhou Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

随机推荐

  1. 开源数据库中间件-MyCat

    开源数据库中间件-MyCat产生的背景 如今随着互联网的发展,数据的量级也是成指数的增长,从GB到TB到PB.对数据的各种操作也是愈加的困难,传统的关系型数据库已经无法满足快速查询与插入数据的需求.这 ...

  2. Volatile小结

    1)Java 中能创建 Volatile 数组吗? 能,Java 中可以创建 volatile 类型数组,不过只是一个指向数组的引用,而不是整个数组.我的意思是,如果改变引用指向的数组,将会受到 vo ...

  3. docker时区正常,但java获得的时间早了8小时解决方法

    我解决容器时区的方法是挂载宿主机的/etc/localtime 到容器的/etc/localtime,这时输入date命令容器时区显示正常,但是跑在容器中的java项目取到的时间却早了8小时. 查阅相 ...

  4. linux 查看CPU内存 网络 流量 磁盘 IO

    使用vmstat命令来察看系统资源情况 在命令行方式下,如何查看CPU.内存的使用情况,网络流量和磁盘I/O? Q: 在命令行方式下,如何查看CPU.内存的使用情况,网络流量和磁盘I/O? A: 在命 ...

  5. android json 解析 kotlin

    前面 写了一次 kotlin解析json 但是,真的写得太烂,直接删掉了,现在重新整理一下.顺便记录一下今天坑了我很久的小问题. 1.首先从最简单的入手吧 一个json的字符串:=====就叫做jso ...

  6. P2065 贪心的果农

    P2065 贪心的果农 题目描述 果农的花园里种着N棵果树.收获的季节终于来到了,果农决定,在接下来的M天时间里完成自己的收获工作.他的收获方式极其暴力——他将会将某棵果树砍倒来获取上面的果实.然而如 ...

  7. P1194 买礼物(建模)

    P1194 买礼物 题目描述 又到了一年一度的明明生日了,明明想要买B样东西,巧的是,这B样东西价格都是A元. 但是,商店老板说最近有促销活动,也就是: 如果你买了第I样东西,再买第J样,那么就可以只 ...

  8. Redis实现之字典跳跃表

    跳跃表 跳跃表是一种有序数据结构,它通过在每个节点中维持多个指向其他节点的指针,从而达到快速访问节点的目的.跳跃表支持平均O(logN).最坏O(N)的时间复杂度查找,还可以通过顺序性操作来批量处理节 ...

  9. 【palindrome partitioning II】cpp

    题目: Given a string s, partition s such that every substring of the partition is a palindrome. Return ...

  10. JMeter非GUI界面运行

    JMeter是一款可以用于做接口可以用于作压力性能的应用程序,该程序是纯Java语音开发,所有对环境支持都比较好. JMeter可以运行模式有两种,一种是UI图形,另一种是命令模式运行也就是非GUI模 ...