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. servlet获得完整路径

    request.getQueryString() request.getParameterMap() request.getParameterNames() 在servlet中GET请求可以通过Htt ...

  2. nodejs报错 events.js:72 throw er; // Unhandled 'error' event

    var http = require('http'); var handlerRequest = function(req,res){ res.end('hello');}; var webServe ...

  3. 两个iframe联动刷新 JS代码

    1.iframe代码: <iframe id="famUpload" src="report.asp?syear=<%=Year(now())%>&qu ...

  4. sql 列设置默认值,语法查询知识点积累

    一.修改字段默认值 alter table 表名 drop constraint 约束名字   ------说明:删除表的字段的原有约束 alter table 表名 add constraint 约 ...

  5. PHP获取客户端操作系统,浏览器,语言,IP,IP归属地等

    <?php class Client { ////获得访客浏览器类型 function Get_Browser(){ if(!empty($_SERVER['HTTP_USER_AGENT']) ...

  6. linux查找命令find

    -1 linux的查找命令有两个: locate find locate:有一个索引库,故速度快,但是新加入的一般不再索引库中,故可能无法查到 find:搜索速度慢,但是功能及其强大,可以追加命令动作 ...

  7. Win7网络检测 WindowsAPICodePack

    原文:http://www.cnblogs.com/yincheng01/archive/2010/05/30/2213234.html 在Windows7操作系统下,支持的网络类型越来越复杂,微软提 ...

  8. VIJOS 1889 天真的因数分解(莫比乌斯反演,容斥原理)

    https://vijos.org/p/1889 同BZOJ2440..,不过这题要求的是有因数因子的,所以莫比乌斯函数要稍微改一下 #include<algorithm> #includ ...

  9. unity3d 导出 Excel

    我在unity里需要导出成Excel格式,试了一些方法,其中用c#的com组件的我还没成功不知道该怎么在unity里调用,(如果哪位大哥用别的方法在unity里成功了,可以交流下,最好给我一个小dem ...

  10. Google map v3 using simple tool file google.map.util.js v 1.0

    /** * GOOGLE地图开发使用工具 * @author BOONYACHENGDU@GMAIL.COM * @date 2013-08-23 * @notice 地图容器的(div)z-inde ...