題目描述
讀十進位字串(optional−,整數1..6digits,可leading0;optional .後1..6digits),求CLDR-like operands n=abs exact value、i=floor(n)、v=小數原位數、w=刪尾0後位數、f=原小數digits解整數、t=刪尾0後digits解整數(無小數/全0則0)。1與1.0的n/i相同但v不同。 給最多6個ordered category rules,category名字小寫,rule用postfix boolean tokens。Atom格式operand mod divisor relation ranges:operand為n/i/v/w/f/t,divisor0代表不mod否則1..100,relation IN/WITHIN/NOTIN/NOTWITHIN,ranges為1..3組整數閉區間lo hi(0..1000),IN要求結果是整數且在某區間,WITHIN允rational;NOT是整個predicate反轉。mod對非負rational用x-floor(x/d)*d。postfix運算AND/OR/NOT完全明定,輸第一true category,皆false為other(rules不能命名other)。 輸每number operands六個(n最簡fraction其餘integer)與category。Q<=20、每rule<=12tokens。這是提供規則的plural selector,不使用OS locale。core visible fraction operand preservation、integer IN與rational WITHIN不同、mod與ordered rule precedence。
輸入格式
R Q;每rule先category tokenCount,再各token一行:ATOM operand divisor relation k及k組lo hi,或AND/OR/NOT。最後Q行十進位字串。
輸出格式
每number一行n i v w f t category,n最簡fraction,其他operands整數。
限制
0≤R≤6;1≤Q≤20;每rule1..12tokens且合法postfix;category互異小寫長1..10且不為other;每atom1..3ranges、0≤lo≤hi≤1000、divisor0..100;number語法如題意。
範例說明
範例一one需i=1且v=0,因此1與001為one,1.0及1.00都是other。範例二1.5不符合integer IN1..2,但符合WITHIN,輸fraction;2.00整數值符合第一rule。
範例測資
範例輸入 1
1 5 one 3 ATOM i 0 IN 1 1 1 ATOM v 0 IN 1 0 0 AND 1 1.0 1.00 001 -1.25
範例輸出 1
1/1 1 0 0 0 0 one 1/1 1 1 0 0 0 other 1/1 1 2 0 0 0 other 1/1 1 0 0 0 0 one 5/4 1 2 2 25 25 other
範例輸入 2
2 3 integer 1 ATOM n 0 IN 1 1 2 fraction 1 ATOM n 0 WITHIN 1 1 2 1.5 2.00 0.9
範例輸出 2
3/2 1 1 1 5 5 fraction 2/1 2 2 0 0 0 integer 9/10 0 1 1 9 9 other
討論與題解
載入討論區…