537 - Artificial Intelligence?
来源:互联网 发布:平面设计书籍 知乎 编辑:程序博客网 时间:2024/04/26 17:49
#include <cstdio>#include <cstring>#include <ctype.h>int main(){ int n,i,j,flag,count; double I,P,U; char str[130]; char num[20]; i=1; scanf("%d",&n); getchar(); while(i<=n) { memset(str,0,sizeof(str)); I=P=U=count=flag=0; fgets(str,100,stdin); for(j=0; j<strlen(str); j++) { if(str[j]=='I'&&str[j+1]=='=') flag=1; else if(str[j]=='U'&&str[j+1]=='=') flag=2; else if(str[j]=='P'&&str[j+1]=='=') flag=3; if((str[j]<='9'&&str[j]>='0')||str[j]=='.') num[count++]=str[j]; else { int y(0); if(flag==1) { for(int x=0; x<strlen(num); x++) { if(num[x]<='9'&&num[x]>='0') I=I*10+num[x]-'0'; if(num[x]=='.') y=x; } if(y!=0) { y=strlen(num)-1-y; while(y--) I=I/10; } } if(flag==2) { for(int x=0; x<strlen(num); x++) { if(num[x]<='9'&&num[x]>='0') U=U*10+num[x]-'0'; if(num[x]=='.') y=x; } if(y!=0) { y=strlen(num)-1-y; while(y--) U=U/10; } } if(flag==3) { for(int x=0; x<strlen(num); x++) { if(num[x]<='9'&&num[x]>='0') P=P*10+num[x]-'0'; if(num[x]=='.') y=x; } if(y!=0) { y=strlen(num)-1-y; while(y--) P=P/10; } } if(str[j]=='m'&&(str[j-1]>='0'&&str[j-1]<='9')) { if(flag==1) I=I/1000; else if(flag==3) P=P/1000; else if(flag==2)U=U/1000; } else if(str[j]=='k'&&(str[j-1]>='0'&&str[j-1]<='9')) { if(flag==1) I=I*1000; else if(flag==3) P=P*1000; else if(flag==2)U=U*1000; } else if(str[j]=='M'&&(str[j-1]>='0'&&str[j-1]<='9')) { if(flag==1) I=I*1000000; else if(flag==3) P=P*1000000; else if(flag==2)U=U*1000000; } memset(num,0,sizeof(num)); count=0; } } printf("Problem #%d\n",i); if(I==0) printf("I=%.2lfA\n\n",P/U); else if(P==0) printf("P=%.2lfW\n\n",U*I); else printf("U=%.2lfV\n\n",P/I); i++; } return 0;}