Help him

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 248    Accepted Submission(s): 58

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$\leq a \leq b \leq 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
 
Recommend
heyang   |   We have carefully selected several similar problems for you:  5061 5060 5057 5056 5053 
 

SB了。。

以后 注意点用atoi...  可能过long long 用 strtoll

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char S[200];
char C[200];
int len;
long long a,b;
int getans(char *A)
{
int i;
int lena=strlen(A);
if(lena==0) return 0;
if(lena!=1&&A[0]=='0') return 0;
for(i=0;i<lena;i++)
if(!('0'<=A[i]&&A[i]<='9')) return 0;
return 1;
}
int main()
{
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
int ans;
long long k;
while(gets(S)!=NULL)
{
scanf("%I64d%I64d",&a,&b);
gets(C);
len=strlen(S);
if(S[0]=='-'&&S[1]=='0') { printf("NO\n");continue;}
if(len>11||len==0) { printf("NO\n");continue;}
if(len==11&&S[0]!='-') { printf("NO\n");continue;}
if(S[0]=='-')
ans=getans(S+1);
else ans=getans(S);
if(!ans) { printf("NO\n");continue;}
else
{
k=strtoll(S,NULL,10);
if(a<=k&&k<=b) printf("YES\n");
else printf("NO\n");
}
memset(S,0,sizeof(S));
}
return 0;
}

学长的十分美好的代码

const int N = 105;
char s[N], t[N];
int a, b, c;
bool solve(){
if(sscanf(s, "%d", &c) != 1) return 0;
sprintf(t, "%d", c);
if(strcmp(s, t) != 0) return 0;
return a<=c && c<=b;
}
int main(){
//freopen("in.txt", "r", stdin);
while(gets(s)){
scanf("%d%d", &a, &b);
getchar();
bool ans = solve();
puts(ans ? "YES" : "NO");
}
return 0;
}

Bestcoder HDU5059 Help him 字符串处理的更多相关文章

  1. 字符串处理 BestCoder Round #43 1001 pog loves szh I

    题目传送门 /* 字符串处理:是一道水题,但是WA了3次,要注意是没有加'\0'的字符串不要用%s输出,否则在多组测试时输出多余的字符 */ #include <cstdio> #incl ...

  2. hdu 4908 BestCoder Sequence 发现M中值是字符串数, 需要预处理

    BestCoder Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  3. BestCoder Round #89 02单调队列优化dp

    1.BestCoder Round #89 2.总结:4个题,只能做A.B,全都靠hack上分.. 01  HDU 5944   水 1.题意:一个字符串,求有多少组字符y,r,x的下标能组成等比数列 ...

  4. BestCoder 1st Anniversary B.Hidden String DFS

    B. Hidden String Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/co ...

  5. BestCoder Round #88

    传送门:BestCoder Round #88 分析: A题统计字符串中连续字串全为q的个数,预处理以下或加个cnt就好了: 代码: #include <cstdio> #include ...

  6. hdu 5311 Hidden String (BestCoder 1st Anniversary ($))(深搜)

    http://acm.hdu.edu.cn/showproblem.php?pid=5311 Hidden String Time Limit: 2000/1000 MS (Java/Others)  ...

  7. BestCoder Round #14

    Harry And Physical Teacher Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  8. hdu5635 BestCoder Round #74 (div.2)

    LCP Array  Accepts: 131  Submissions: 1352  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: 13 ...

  9. 【BestCoder】【Round#41】

    枚举+组合数?+DP+数学问题 http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=582 QAQ许久没打过比赛,来一发BC,结果还是只 ...

随机推荐

  1. NET基础课--Linq第一讲

    在说LINQ之前必须先说说几个重要的C#语言特性 一:与LINQ有关的语言特性 1.隐式类型 (1)源起 在隐式类型出现之前,在声明一个变量的时候, 总是要为一个变量指定他的类型甚至在foreach一 ...

  2. .Net+EF连接Oracle 10、11 开发,ODAC安装配置与使用详解

    Oracle数据访问组件 (ODAC)  全称:Oracle Data Access Components 优点:由于微软在.net framework4中会将System.Data.OracleCl ...

  3. 原生Javascript实现图片轮播效果

    首先引入js运动框架 function getStyle(obj,name){ if(obj.currentStyle){ return obj.currentStyle[name]; } else{ ...

  4. asp.net UpdatePanel 不能局部刷新问题汇总

    1.web.config 配置问题.   关于web.config的配置方面网上有很多资料参考,按照其方法做即可实现. 2.网站 Framework 版本变化造成不能局部刷新问题    版本更新时,会 ...

  5. 嵌入式Linux LED小灯点亮实验

    问:怎么写LED驱动程序? 1.搭建一个字符驱动的框架(上一节已经完成) 2.完善硬件的操作 问:驱动里操作硬件寄存器与单片机操作硬件寄存器有什么不一样的地方? 答:单片机操作的寄存器地址是物理地址, ...

  6. Java的反射机制及应用实例

    一:什么是反射机制 简单的来说,反射机制指的是程序在运行时能够获取自身的信息.在Java中,只要给定类的名字,那么就可以通过反射机制来获得类的所有信息. 二:哪里用到反射机制 我们用过一些知识,但是并 ...

  7. web中的中文字体的英文名称

    自从font-face出现以后,字体样式就不再是web开发者的难题了,但是对于移动端的中文来说,问题还是存在的,因为中文文件大小最少要3M+,即使选择性的加载某个字的字体,那也会出现不易替换的问题,所 ...

  8. http://www.cnblogs.com/Joyes1989/archive/2013/06/28/3161739.html centos 输入法安装切换

    昨天装了一个centos  安装输入法的时候  让我有点纠结  全英文的 读不懂

  9. 【转】Objective-C 与 Runtime:为什么是这样?

    原文地址: http://t.cn/RyyNIXd?u=2483713130&m=3884400301576073&cu=2483713130 笔者非常高兴能为Objective-C写 ...

  10. google浏览器翻译失败解决方案

    用记事本打开 C:\Windows\System32\drivers\etc下hosts文件 在文件末尾加入如下两行 203.208.46.145 translate.google.com 203.2 ...