当前位置:网站首页>B - identify floating point constant problems
B - identify floating point constant problems
2022-07-29 05:32:00 【Xiao Hong is working hard】
When doing this topic WA A lot of time , Finally, all the schemes that are not allowed are summarized
Cases that are not allowed :
1. Separate integer types . example :1
2. If the first character of the input string is not ‘+’ or ‘-’. example :/1.0
3. Integer or floating-point type followed by (‘e’ or ‘E’) Or other characters . example :1.0e perhaps 1.0/
4.‘e’ or ‘E’ Only connect to the back (‘+’ or ‘-’) Or other characters . example :1.0e+ perhaps 1.0e/
5.‘+’ or ‘-’ Followed by "0-9" String other than . example :1.0e+/
matters needing attention :
‘e’ or ‘E’ hinder ‘+’ It can be omitted . example :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;
}
}
}
Thank you for your ideas :https://blog.csdn.net/godsight/article/details/53219109
边栏推荐
- Camunda 1、Camunda工作流-介绍
- Best practices of JD cloud Distributed Link Tracking in financial scenarios
- Best practices for elastic computing in the game industry
- 题解:在一个排序数组中查找元素第一个和最后一个的位置 (个人笔记)
- AiTalk创始人梁宇淇:镜像连接虚拟与现实的纽带
- 200 多家 ISV 入驻!阿里云计算巢发布一周年
- 167. Sum of two numbers II - enter an ordered array
- 来!看排名一年上升16位的ClickHouse,如何在京东落地实践
- 【C语言系列】— 把同学弄糊涂的 “常量” 与 “变量”
- Cmu15-213 malloc lab experiment record
猜你喜欢
200 多家 ISV 入驻!阿里云计算巢发布一周年
【C语言系列】— 把同学弄糊涂的 “常量” 与 “变量”
抢先预约 | 阿里云无影云应用线上发布会预约开启
365 day challenge leetcode 1000 questions - day 037 elements and the maximum side length of squares less than or equal to the threshold + the number of subsequences that meet the conditions
浅谈范式
[event preview] cloud digital factory and digital transformation and innovation forum for small and medium-sized enterprises
More than 200 ISVs have settled in! The first anniversary of Alibaba cloud computing nest
C语言 一级指针
Live broadcast preview | how to save 30% labor cost and shorten 80% trademark processing cycle?
【C语言系列】—三种方法模拟实现strlen库函数的方法
随机推荐
Occt learning 002 - environment construction
WDDM learning
With cloud simulation platform, Shichuang technology supports the upgrading of "China smart manufacturing"
Bubble sort c language
Live broadcast Preview: integration of JD cloud Devops and jfrog product library
【剑指offer】— 详解库函数atoi以及模拟实现atoi函数
【C语言系列】— 字符串+部分转义字符详解+注释小技巧
【C语言系列】— 一道递归小题目
C语言 一维数组
C语言 N皇后问题
With frequent data leakage and deletion events, how should enterprises build a security defense line?
Alibaba cloud Zhang Xintao: heterogeneous computing provides surging power for the digital economy
Solution: find the position of the first and last element in a sorted array (personal notes)
Together with digital people, digital space and XR platform, Alibaba cloud and its partners jointly build a "new vision"
【C语言系列】— 把同学弄糊涂的 “常量” 与 “变量”
英伟达周锡健:设计到数字营销的最后一公里
Cryengine5 shader debugging
paddle.fluild常量计算报错‘NoneType‘ object has no attribute ‘get_fetch_list‘
Cryengine3 debugging shader method
R & D efficiency | analysis of kubernetes' core technology and Devops' landing experience