ACM 537 Artificial Intelligence
作法:暴力題
沒什麼好說的
/*********************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
main()
{
int n;
char x[101];
int a,b,c,d;
while(scanf("%d ",&n)==1)
{
/*因為下面有gets*/
for(a=1;a<=n;a++)
{
double P=0,I=0,U=0;
int flagP=0,flagI=0,flagU=0; /* 有 可 能 P I U 給 0 !*/
gets(x);
int m=strlen(x),temp[500]={0};
for(b=0;b<m;b++) temp[b]=x[b];/*我怕RE*/
for(b=0;b<m;b++)
{
if(temp[b]=='P'&&temp[b+1]=='=')
{
flagP=1;
for(b=b+2;b<m;b++)
if(temp[b]<=57&&temp[b]>=48) P=P*10+temp[b]-48;
else if(temp[b]=='.')
{
double temp1=1;
for(b=b+1;b<m;b++)
if(temp[b]<=57&&temp[b]>=48) {temp1=temp1/10;P=P+temp1*(temp[b]-48);}
else break;
break;
}
else break;
if(temp[b]=='M') P=P*1000000;
else if(temp[b]=='m') P=P*0.001;
else if(temp[b]=='k') P=P*1000;
}
if(temp[b]=='I'&&temp[b+1]=='=')
{
flagI=1;
for(b=b+2;b<m;b++)
if(temp[b]<=57&&temp[b]>=48) I=I*10+temp[b]-48;
else if(temp[b]=='.')
{
double temp1=1;
for(b=b+1;b<m;b++)
if(temp[b]<=57&&temp[b]>=48) {temp1=temp1/10;I=I+temp1*(temp[b]-48);}
else break;
break;
}
else break;
if(temp[b]=='M') I=I*1000000;
else if(temp[b]=='m') I=I*0.001;
else if(temp[b]=='k') I=I*1000;
}
if(temp[b]=='U'&&temp[b+1]=='=')
{
flagU=1;
for(b=b+2;b<m;b++)
if(temp[b]<=57&&temp[b]>=48) U=U*10+temp[b]-48;
else if(temp[b]=='.')
{
double temp1=1;
for(b=b+1;b<m;b++)
if(temp[b]<=57&&temp[b]>=48) {temp1=temp1/10;U=U+temp1*(temp[b]-48);}
else break;
break;
}
else break;
if(temp[b]=='M') U=U*1000000;
else if(temp[b]=='m') U=U*0.001;
else if(temp[b]=='k') U=U*1000;
}
}
/* printf("%lf %lf %lf\n",P,I,U); */
printf("Problem #%d\n",a);
if(flagI==1&&flagU==1)/*P=I*U*/
printf("P=%.2lfW\n",I*U);
else if(flagI==1&&flagP==1)/*P/I=U*/
printf("U=%.2lfV\n",P/I);
else/*P/U=I*/
printf("I=%.2lfA\n",P/U);
}
}
return 0;
}