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. map的类型映射

    以下是使用STL中map类型,对类型的转换示例,主要可以解决的问题,也就是一般的类型之间的相互转换,可以较好的解决相关的问题. 以下是C++源码,比较简短,容易理解的. #include " ...

  2. 关于EventHandler的使用

    也就是委托和事件的使用.使用过,但了解的不够深入,现在逐渐来填以前留下的坑吧. EventHandler, EventHandler<TEventArg> 是.net Framework内 ...

  3. 【.Net Remoting-1】

    [.NetRemoting]2015.09.16 [分布式应用程序] 应用程序分布在不同计算机上,通过网络来共同完成一项任务 C/S架构[模式] [互操作性,Interoperability]又称[互 ...

  4. jxl 使用

    public static void main(String args[]) {try {// 打开文件WritableWorkbook book = Workbook.createWorkbook( ...

  5. 使用Win32 API 查找文件

    头文件:#include <windows.h> //FindFirstFile() 获得指定目录的第一个文件 HANDLE FindFirstFile( LPCTSTR lpFileNa ...

  6. Java—Integer类

    Integer类 Integer 类在对象中包装了一个基本类型 int 的值.Integer 类型的对象包含一个 int 类型的字段. 该类提供了多个方法,能在 int 类型和 String 类型之间 ...

  7. C语言实现界面(不通过MFC\避免遗忘)

    感觉MFC不属于程序员细究的东西,今实现基本界面避免日后遗忘. 源代码: #include<windows.h>#include<stdio.h>char str[] = {' ...

  8. (原)下载pubFig的python代码

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5715305.html pubFig数据库网址: http://www.cs.columbia.edu/ ...

  9. Js之History对象

    Window对象的history属性引用的是该窗口的History对象.History对象是用来把窗口的浏览历史用文档和文档状态列表的形式表示.History对象的length属牲表示浏览历史列表中的 ...

  10. inotifywait实现目录监控

    http://blog.csdn.net/firefoxbug/article/details/8188804