首页 > 其他 > 详细

HDU1409 Is It a Number

时间:2017-09-06 19:05:55      阅读:280      评论:0      收藏:0      [点我收藏+]

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 }

 

HDU1409 Is It a Number

原文:http://www.cnblogs.com/yinghualuowu/p/7486117.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!