HDU1409 Is It a Number

http://acm.hdu.edu.cn/showproblem.php?pid=1409

没啥好说的,至今也不知道到底错在哪里了,看了discuss才过的

复制代码
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <algorithm>
 4 #include <vector>
 5 #include <string.h>
 6 #include <map>
 7 using namespace std;
 8 char s[12345];
 9 int solve(char *s){
10     int i=0;
11     int len=strlen(s);
12     while(s[i]>='0'&&s[i]<='9'){
13         i++;
14     }
15 
16     if(i==len){
17         return 1;
18     }
19     if(s[i]=='.'){
20         i++;
21         while(s[i]>='0'&&s[i]<='9'){
22             i++;
23         }
24         if(i==len){
25             return 1;
26         }
27         if(s[i]=='E'){
28             i++;
29             if(s[i]=='+'||s[i]=='-'){
30                 i++;
31             }
32             if(i==len){
33                 return 0;
34             }
35             while(s[i]>='0'&&s[i]<='9'){
36                 i++;
37             }
38             if(i==len){
39                 return 1;
40             }
41             return 0;
42         }
43     }else if(s[i]=='E'){
44         if(i==0){
45             return 0;
46         }
47         i++;
48         if(s[i]=='+'||s[i]=='-'){
49                 i++;
50         }
51         if(i==len){
52             return 0;
53         }
54         while(s[i]>='0'&&s[i]<='9'){
55                 i++;
56         }
57         if(i==len){
58             return 1;
59         }
60         return 0;
61     }
62     return 0;
63 }
64 int t;
65 int main(){
66     scanf("%d",&t);
67     getchar();
68     while(t--){
69         gets(s);
70         if(solve(s)){
71             cout<<"YES"<<endl;
72         }else{
73             cout<<"NO"<<endl;
74         }
75     }
76     return 0;
77 }
复制代码

 

posted @   樱花落舞  阅读(167)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示