中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 未整理篇
acm.jlu.edu.cn-1552-IdentifyingLegalPascalRealConstants
作者:macox 时间:2003-02-18 11:10 出处:互联网 责编:chinaitpower
              摘要:acm.jlu.edu.cn-1552-IdentifyingLegalPascalRealConstants

Pascal requires that real constants have either a decimal point, or an exponent (starting with the letter e or E, and officially called a scale factor), or both, in addition to the usual collection of decimal digits. If a decimal point is included it must have at least one decimal digit on each side of it. As expected, a sign (+ or -) may precede the entire number, or the exponent, or both. Exponents may not include fractional digits. Blanks may precede or follow the real constant, but they may not be embedded within it. Note that the Pascal syntax rules for real constants make no assumptions about the range of real values, and neither does this problem.

Your task in this problem is to identify legal Pascal real constants.

Input and Output

Each line of the input data contains a candidate which you are to classify. For each line of the input, display your finding as illustrated in the example shown below. The input terminates with a line that contains only an asterisk in column one.

Sample Input

1.2
   1.
  1.0e-55
  e-12
    6.5E
     1e-12
  +4.1234567890E-99999
   7.6e+12.5
99
*

Sample Output

1.2 is legal.
1. is illegal.
1.0e-55 is legal.
e-12 is illegal.
6.5E is illegal.
1e-12 is legal.
+4.1234567890E-99999 is legal.
7.6e+12.5 is illegal.
99 is illegal.





#include<iostream> #include<memory> using namespace std; void main() { enum State{PRE_NUM,SIGN1,PRE_POINT,POINT,FRACTION,E,SIGN2,EXP,FOLLOWBLANK,ERROR}; char ch; char str[1000]; State state; while(cin>>ch,ch!='*') { int idx=0; state=PRE_NUM; while(ch!='\n') { switch(state) { case PRE_NUM: if(ch=='+'||ch=='-') { state=SIGN1; break; } if(ch>='0'&&ch<='9') { state=PRE_POINT; break; } state=ERROR; break; case SIGN1: if(ch>='0'&&ch<='9') { state=PRE_POINT; } else state=ERROR; break; case PRE_POINT: if(ch=='.') { state=POINT; break; } if(ch=='e'||ch=='E') { state=E; break; } if(!(ch>='0'&&ch<='9')) { state=ERROR; } break; case POINT: if(ch>='0'&&ch<='9') { state=FRACTION; } else state=ERROR; break; case FRACTION: if(ch=='e'||ch=='E') { state=E; break; } if(ch==' ') { state=FOLLOWBLANK; break; } if(!(ch>='0'&&ch<='9')) { state=ERROR; } break; case E: if(ch=='+'||ch=='-') { state=SIGN2; break; } if(ch>='0'&&ch<='9') { state=EXP; break; } state=ERROR; break; case SIGN2: if(ch>='0'&&ch<='9') { state=EXP; } else state=ERROR; break; case EXP: if(ch==' ') { state=FOLLOWBLANK; break; } if(!(ch>='0'&&ch<='9')) state=ERROR; break; case FOLLOWBLANK: if(ch!=' ') state=ERROR; default: break; } str[idx++]=ch; cin.get(ch); } str[idx]='\0'; while(str[--idx]==' ') str[idx]='\0'; cout<<str<<" is "; if(state==ERROR||state==PRE_POINT||state==POINT||state==SIGN1||state==SIGN2||state==E) cout<<"illegal.\n"; else cout<<"legal.\n"; memset(str,0,++idx*sizeof(char)); } }

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有