当前位置:网站首页>B - 识别浮点常量问题
B - 识别浮点常量问题
2022-07-29 05:09:00 【小洪正在努力】

做这个题目的时候WA了很多次,最终总结出了所有不被允许的方案
不被允许的案例:
1.单独整数类型。例:1
2.输入的字符串最前面的字符如果不为‘+’或‘-’。例:/1.0
3.整型或浮点类型后只接(‘e’或‘E’)或接其他字符。例:1.0e或者1.0/
4.‘e’或‘E’后面只接(‘+’或‘-’)或接其他字符。例:1.0e+或者1.0e/
5.‘+’或‘-’后面接"0-9"以外的字符串。例:1.0e+/
注意事项:
‘e’或‘E’后面的‘+’可以省略。例:1.0e10
#include<bits/stdc++.h>
using namespace std;
string s;
int p;
int is_int()
{
int flag=0;
if(s[p]>='0'&&s[p]<='9')
{
p++;
flag=1;
while(1)
{
if(s[p]>='0'&&s[p]<='9')
p++;
else
break;
}
}
return flag;
}
int is_float()
{
int flag=0;
if(is_int())
{
flag=1;
if(s[p]=='.')
{
p++;
if(is_int())
flag=2;
else
flag=0;
}
}
return flag;
}
int main()
{
int len;
while(cin>>s)
{
len = s.length();
p=0;
if(s[p]==' ')p++;
if(s[p]=='+'||s[p]=='-')p++;
int flag;
if(flag=is_float())
{
if(flag==1&&p==len)
cout<<"NO"<<endl;
else if(flag==2&&p==len)
cout<<"YES"<<endl;
else
{
if(s[p]=='e'||s[p]=='E')
{
p++;
if(s[p]=='+'||s[p]=='-')
{
p++;
}
if(is_int())
{
if(p==len)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
else
{
cout<<"NO"<<endl;
}
}
}
else
{
cout<<"NO"<<endl;
}
}
}
感谢大佬提供的思路:https://blog.csdn.net/godsight/article/details/53219109
边栏推荐
- Yangyonglin, vice president of Rushi Technology: when traditional industries encounter "digital space"
- 千人规模互联网公司研发效能成功之路
- Occt learning 002 - environment construction
- [event preview] cloud digital factory and digital transformation and innovation forum for small and medium-sized enterprises
- CMake 设置vs启动运行环境路径
- 为啥谷歌的内部工具不适合你?
- 数组学习之入门简单题 两数之和
- 哈夫曼树以及哈夫曼编码在文件压缩上的应用
- What is_ GLIBCXX_ VISIBILITY(default)
- 510000 prize pool invites you to fight! The second Alibaba cloud ECS cloudbuild developer competition is coming
猜你喜欢

R & D efficiency | analysis of kubernetes' core technology and Devops' landing experience

研发效能|Kubernetes核心技术剖析和DevOps落地经验

京东云金秋上云特惠进行中!扫码参与活动

Alibaba cloud Zhang Xintao: heterogeneous computing provides surging power for the digital economy

365 day challenge leetcode 1000 questions - day 040 design jump table + avoid flooding + find the latest grouping with size M + color ball with reduced sales value

365天挑战LeetCode1000题——Day 037 元素和小于等于阈值的正方形的最大边长 + 满足条件的子序列数目

C language handwritten qq-ai version

NVIDIA Zhou Xijian: the last mile from design to digital marketing

京东云联合Forrester咨询发布混合云报告 云原生成为驱动产业发展新引擎

Handwritten student management system
随机推荐
C语言数组典型应用代码详细讲解—高手误入(逐步代码详解)
Xiaobai high salary shortcut Qt development game Snake
R & D efficiency | analysis of kubernetes' core technology and Devops' landing experience
Best practices for elastic computing in the game industry
重定向和文件
WDDM learning
京东云分布式链路追踪在金融场景的最佳实践
How rimworld uploads creative workshops through steamcmd
Why is Google's internal tools not suitable for you?
2022数学建模竞赛暑期培训讲座——最优化方法:目标规划
Day 5
京东云金秋上云特惠进行中!扫码参与活动
167. 两数之和 II - 输入有序数组
365 day challenge leetcode 1000 questions - day 039 full binary tree inserter + find peak II + snapshot array
QML type: state state
Preemptive appointment | Alibaba cloud shadowless cloud application online conference appointment opens
副作用和序列点
【C语言系列】—深度解剖数据在内存中的存储(一) 暑假开篇
Alibaba cloud architect details nine trends in the game industry
OCCT学习002-----环境搭建