poj 3332-判断字符串是否合法
来源:互联网 发布:好听的名字知乎 编辑:程序博客网 时间:2024/05/17 22:56
Description
Write a program that read a line of input and checks if the line contains a valid real number. Real numbers may have a decimal point, an exponent (starting with the character e or E), or both. Additionally, it has the usual collection of decimal digits. If there is a decimal point, there must be at least one digit on each side of the point. There may be a plus or minus sign in front of the number, or the exponent, or both (without any blank characters after the sign). Exponents are integers (not having decimal points). There may be blank characters before or after a number, but not inside it. Note that there is no bound on the range of the numbers in the input, but for the sake of simplicity, you may assume the input strings are not longer than 1000 characters.
Input
The first line of the input contains a single integer T which is the number of test cases, followed by T lines each containing the input line for a test case.
Output
The output contains T lines, each having a string which is LEGAL or ILLEGAL.
Sample Input
2 1.5e+23.
Sample Output
LEGALILLEGAL
模拟:
#include <iostream>#include <string.h>#include <algorithm>#include <math.h>#include <string>#include <stdio.h>#include <ctype.h>using namespace std;char s[1200];int main() {int T;scanf("%d", &T);while (T --) {scanf(" %s", s);if(s[0] == '+' || s[0] == '-' || isdigit(s[0])) {int c1 = 0;int c2 = 0;int i;for (i = 1; s[i] != '\0'; i ++) {if(s[i] == '.') {c1 ++;if(!isdigit(s[i - 1]) || !isdigit(s[i + 1])) c1 = 2; if(c1 > 1 || c2 > 0) {c1 = 2;break;}}else if(s[i] == 'E' || s[i] == 'e') {c2 ++;if(!isdigit(s[i-1]))c2 = 2;if(c2 > 1) {c1 = 2;break;}}else if(!isdigit(s[i])) {if(!isdigit(s[i-1]) && s[i-1] != '.'&& s[i-1] != 'E' && s[i-1]!='e') {c1 = 2;break;}}}if(!isdigit(s[i-1]))c1 = 2;if(c1==2)puts("ILLEGAL");elseputs("LEGAL");}elseputs("ILLEGAL");}return 0;}
- poj 3332-判断字符串是否合法
- 判断一个字符串是否合法
- C#判断字符串是否合法
- js判断字符串是否合法
- JavaScript判断字符串是否合法
- JS判断字符串格式是否合法
- JS判断字符串格式是否合法
- java判断生日字符串是否合法
- 判断指定格式字符串是否合法
- 字符串——判断IP是否合法
- js 运算的字符串 判断运算是否合法
- poj 1056 Trie树判断哈夫曼编码是否合法
- 判断输入的IP V4地址字符串是否合法
- javascript判断日期是否合法
- c#判断身份证是否合法
- 判断十六进制数据是否合法
- 判断文件名是否合法
- 代码判断邮箱是否合法
- win2003关闭"显示关闭事件跟踪程序
- QQ聊天
- 展讯最新资料大全
- 使用多线程实现把键盘的输入显示在屏幕上和存在指定磁盘中
- Linux下NFS服务器的配置
- poj 3332-判断字符串是否合法
- 高效使用auto_ptr
- 素数和最大公约数
- openstack Glance的镜像缓存机制介绍
- Bigcommerce系统瘦身方法——加快运行速度
- chapt14、探索虚拟内存
- 未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序
- 关于多线程实现火车票售票模拟
- 问题总结