time limit: 1000 ms memory limit: 65536 kib
submit
statistic
problem description
編譯器在對程式進行編譯之前,首先要進行語法分析。通常,程式被分解成若干個小單元,然後和語言的語法模式進行匹配。在分析表示式的時候,變數的型別在變數宣告的時候就決定了;而常量的型別需要從常量的形式來判斷。
假設你是自動編譯器(acm)開發小組的一員,負責pascal語言編譯器的開發。你的任務是分析程式分解模組送來的檔案,判斷其中包含的字串是否合乎語法的pascal浮點常量。
pascal語言對浮點常量的語法要求是:乙個浮點常量除了十進位制數碼之外,必須帶有乙個小數點或乙個指數(緊接在字母e或e之後,在正式文件中也被稱為比例因子)。如果該浮點常量含有小數點,則在小數點兩側都至少要有乙個十進位制數碼。當然,在整個浮點常量或指數之前,也許會出現符號+或-。指數不能包含小數。空格也許會出現在浮點常量的前後,但不會出現在浮點常量中間。
請注意pascal語言的語法規則沒有對浮點數常量的取值範圍作出任何假定。
input
輸入只有一行,就是有待識別的字串。字串的長度不超過255。
output
請將分析的結果按以下樣例的格式輸出。如果輸入檔案中的字串是pascal浮點常量,請輸出字串「yes」,否則輸出字串「no」。
sample input
1.2
sample output
yes
hint
輸入:1 輸出:no
輸入:1.0e-55 輸出:yes
輸入:e-12 輸出:no
輸入:1e-12 輸出:yes
輸入:6.5e 輸出:no
輸入:+4.1234567890e-9999 輸出: yes
source
using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.threading.tasks;
namespace test
return -1;
//前乙個是+或者-
case 2:
if (char.isnumber(c))
return 3;
return -1;
//前乙個是數字
case 3:
if (char.isnumber(c))
return 3;
if (c == '.')
return 4;
if (c == 'e' || c == 'e')
return 6;
return -1;
//前乙個是小數點
case 4:
if (char.isnumber(c))
return 5;
return -1;
//前面有小數點後的數字
case 5:
if (char.isnumber(c))
return 5;
if (c == '\0')
return 0;
if (c == 'e' || c == 'e')
return 6;
return -1;
//前乙個是e或e
case 6:
if (c == '+' || c == '-')
return 7;
if (char.isnumber(c))
return 8;
return -1;
//前乙個是e或e後的+或-
case 7:
if (char.isnumber(c))
return 8;
return -1;
//前面有e的數字
case 8:
if (char.isnumber(c))
return 8;
if (c == '\0')
return 0;
return -1;
default:
return -1;}}
static void main(string args)
k = 0;
for(;i<=j;i++)
s[k] = '\0';
state = 1;
for(i=0;i<=s.length;i++)
if (state == 0)
}if(state==-1)}}
}
識別浮點常量問題
time limit 1000ms memory limit 65536kb submit statistic problem description 編譯器在對程式進行編譯之前,首先要進行語法分析。通常,程式被分解成若干個小單元,然後和語言的語法模式進行匹配。在分析表示式的時候,變數的型別在變數宣...
識別浮點常量問題
time limit 1000ms memory limit 65536kb submit statistic problem description 編譯器在對程式進行編譯之前,首先要進行語法分析。通常,程式被分解成若干個小單元,然後和語言的語法模式進行匹配。在分析表示式的時候,變數的型別在變數宣...
識別浮點常量問題
time limit 1000 ms memory limit 65536 kib problem description 編譯器在對程式進行編譯之前,首先要進行語法分析。通常,程式被分解成若干個小單元,然後和語言的語法模式進行匹配。在分析表示式的時候,變數的型別在變數宣告的時候就決定了 而常量的型...