24h購物| | PChome| 登入
2009-05-10 16:06:24| 人氣557| 回應0 | 上一篇 | 下一篇

ACM 537 Artificial Intelligence

推薦 0 收藏 0 轉貼0 訂閱站台

作法:暴力題

沒什麼好說的

/*********************************************************/

#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;
}

台長: 來源不明
人氣(557) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 數位資訊(科技、網路、通訊、家電) | 個人分類: ACM |
此分類下一篇:ACM 11388 11388 - GCD LCM
此分類上一篇:ACM 409 Excuses, Excuses!

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文