当前位置:网站首页>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
边栏推荐
- 167. Sum of two numbers II - enter an ordered array
- [event preview] cloud digital factory and digital transformation and innovation forum for small and medium-sized enterprises
- Application of Huffman tree and Huffman coding in file compression
- The road to success in R & D efficiency of 1000 person Internet companies
- 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
- 平行云CEO 李岩:CloudXR ,开启通往元宇宙的通道
- ·来一篇编程之路的自我介绍吧·
- C语言 一维数组
- Solution: find the position of the first and last element in a sorted array (personal notes)
- 200 多家 ISV 入驻!阿里云计算巢发布一周年
猜你喜欢

Live broadcast preview | how to improve enterprise immunity through "intelligent edge security"?

C language one-dimensional array

无重复字符的最长字串

【C语言系列】—深度解剖数据在内存中的存储(二)-浮点型

VIM editor use

Alibaba cloud and Dingjie software released the cloud digital factory solution to realize the localized deployment of cloud MES system

365 day challenge leetcode 1000 questions - day 041 two point search completion anniversary + nth magic number + online election

Come on! See how Clickhouse, which has risen 16 places a year, can be implemented in jd.com

Day 3

Vs code的安装步骤及环境配置
随机推荐
【赛事预告】云上开发,高效智能——第二届阿里云ECS CloudBuild开发者大赛即将启动
C语言数组典型应用代码详细讲解—高手误入(逐步代码详解)
Live broadcast Preview: integration of JD cloud Devops and jfrog product library
B - 识别浮点常量问题
C language file operation
【C语言系列】—三种方法模拟实现strlen库函数的方法
无重复字符的最长字串
阿里云架构师梁旭:MES on 云盒,助力客户快速构建数字工厂
Container security open source detection tool - veinmind (mirror backdoor, malicious samples, sensitive information, weak password, etc.)
阿里云张新涛:异构计算为数字经济提供澎湃动力
WDDM learning
QT series - Installation
【C语言系列】— 不创造第三个变量,实现两个数的交换
365 day challenge leetcode 1000 questions - day 042 array sequence number conversion + relative ranking discretization processing
C语言 一级指针
QML type: state state
Pyqt5: Chapter 1, Section 1: creating a user interface using QT components - Introduction
整数溢出和打印
200 多家 ISV 入驻!阿里云计算巢发布一周年
365天挑战LeetCode1000题——Day 035 每日一题 + 二分查找 13