UVA Solution 325 - Identifying Legal Pascal Real Constants - Solution in C, C++ | Volume 3
UVA Online Judge Solution 325 - Identifying Legal Pascal | Volume 3
UVA Problem Link - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=261
Problem Name: 325 - Identifying Legal Pascal
Problem Number : UVA - 325 - Identifying Legal Pascal
Online Judge : UVA Online Judge Solution
Volume: 3
Solution Language : C, C plus plus
UVA Solution 325 - Identifying Legal Pascal Code in C, CPP:
#include <stdio.h> #include <string.h> int main() { char s[1000]; while(gets(s)) { if(!strcmp(s, "*")) break; int i = 0, j = strlen(s)-1; while(s[i] == ' ') i++; while(s[j] == ' ') j--; char trim[1000]; memcpy(trim, s+i, j-i+1); trim[j-i+1] = '\0'; int len = strlen(trim); int error = 0; i = 0; if(trim[i] == '+' || trim[i] == '-') i++; j = i; while(trim[i] >= '0' && trim[i] <= '9' && i < len) i++; if(j == i) error = 1; if(i < len && trim[i] == '.') { i++; j = i; while(trim[i] >= '0' && trim[i] <= '9' && i < len) i++; if(j == i) error = 1; if(i < len && (trim[i] == 'e' || trim[i] == 'E')) { i++; if(trim[i] == '+' || trim[i] == '-') i++; j = i; while(trim[i] >= '0' && trim[i] <= '9' && i < len) i++; if(j == i) error = 1; else if(i < len) {error = 1;} } else if(i < len) {error = 1;} } else if(i < len && (trim[i] == 'e' || trim[i] == 'E')) { i++; if(trim[i] == '+' || trim[i] == '-') i++; j = i; while(trim[i] >= '0' && trim[i] <= '9' && i < len) i++; if(j == i) error = 1; else if(i < len) {error = 1;} } else {error = 1;} if(error) printf("%s is illegal.\n", trim); else printf("%s is legal.\n", trim); } return 0; }
No comments:
Post a Comment