UVa OJ 537-Artificial Intelligence?
2011-01-13 15:23
211 查看
简单的字符串处理:
{ Author:wzx961008 Problem:UVa 537-Artificial Intelligence? Verdict:Accepted Language:PASCAL Run Time:0.012s Submission Date:2011-01-12 09:14:55 } var n,ii,j,t:longint; I,P,U:extended; tp,tu,ti:boolean; question,s:string; procedure calculate(s:string; var Value:extended); var code:longint; begin delete(s,length(s),1); val(s,Value,code); if code<>0 then begin if s[code]='m' then begin delete(s,length(s),1); val(s,Value,code); Value:=Value/1e3; end; if s[code]='k' then begin delete(s,length(s),1); val(s,Value,code); Value:=Value*1e3 end; if s[code]='M' then begin delete(s,length(s),1); val(s,Value,code); Value:=Value*1e6 end; end; end; function ok:boolean; begin if question[t]='A' then exit(true); if question[t]='W' then exit(true); if question[t]='V' then exit(true); ok:=false; end; procedure print; begin writeln('Problem #',ii); if not tp then writeln('P=',I*U:0:2,'W'); if not tu then writeln('U=',P/I:0:2,'V'); if not ti then writeln('I=',P/U:0:2,'A'); writeln; end; begin readln(n); for ii:=1 to n do begin readln(question); tp:=false; tu:=false; ti:=false; for j:=1 to length(question) do if question[j]='=' then begin if question[j-1]='P' then tp:=true; if question[j-1]='U' then tu:=true; if question[j-1]='I' then ti:=true; t:=j; s:=''; repeat inc(t); s:=s+question[t]; if ok then break; until false; if s[length(s)]='W' then calculate(s,P); if s[length(s)]='V' then calculate(s,U); if s[length(s)]='A' then calculate(s,I); end; print; end; end.
相关文章推荐
- UVa OJ 150 - Double Time (双时间)
- UVa OJ 10112-Myacm Triangles
- UVa OJ 10994-Simple Addition
- UVa OJ 10171-Meeting Prof. Miguel...
- SRM 537 div2
- 537 - Artificial Intelligence?
- Uva 537 - Artificial Intelligence?
- Uva Oj 10000 - Longest Paths
- uva 537
- UVA537 - 详解Artificial Intelligence?
- uva 537 - Artificial Intelligence?
- UVA OJ: 414 - Machined Surfaces
- UVaOJ 537 - Artificial Intelligence?
- uva 537 Automatic Poetry
- (题号)UVa OJ全部题目列表
- srm 537
- UVA oj 489 Hangman Judge(字符串)
- 537 - Artificial Intelligence?
- UVa OJ 1331 - Minimax Triangulation
- leetcode 537 Complex Number Multiplication(Medium)