您的位置:首页 > 其它

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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: