zoukankan      html  css  js  c++  java
  • uva 537 Artificial Intelligence?

    这道题目错了三次,代码算法没有任何错误,还是因为哥的英语水品实在让人蛋疼,三次错误都是因为少输出最后的空行,别的不说了,看代码吧

    View Code
     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<math.h>
     4 #define N 20000
     5 int main()
     6 {
     7     int T, r;
     8     scanf("%d",&T);
     9     getchar();
    10     for(r = 1;r <= T; r++)
    11     {
    12         char st[N];
    13         gets(st);
    14         int len = strlen(st), i, j, k, flag;
    15         double P = 0, I = 0, U = 0, temp = 0;
    16         for(i = 0;i < len; i++)
    17         {
    18             flag = 0;
    19             if(st[i] == '=')
    20             {
    21                 temp = 0;
    22                 if(st[i-1] == 'P' || st[i-1] == 'U' || st[i-1] == 'I')
    23                 {
    24                     if(st[i-1] == 'P')
    25                         flag = 1;
    26                     else if(st[i-1] == 'U')
    27                         flag = 2;
    28                     else
    29                         flag = 3;
    30                     k = -1;
    31                     for(j = i+1;st[j] >= '0' && st[j] <= '9'; j++)
    32                     {
    33                         k++;
    34                     }
    35                     i++;
    36                     for(;k >= 0; k--,i++)
    37                     {
    38                         temp += pow(10.0,1.0*k)*(st[i]-'0');
    39                     }
    40                     if(st[i] == '.')
    41                     {
    42                         k = 0;
    43                     for(j = i+1;st[j] >= '0' && st[j] <= '9'; j++)
    44                     {
    45                         k++;
    46                     }
    47                     i = j;
    48                     j--;
    49                     for(;k > 0; k--,j--)
    50                     {
    51                         temp += pow(0.1,1.0*k)*(st[j]-'0');
    52                     }
    53                     }
    54                     if(st[i] == 'm')
    55                         temp *= 0.001;
    56                     else if(st[i] == 'M')
    57                         temp *= 1.0*1000000;
    58                     else if(st[i] == 'k')
    59                         temp *= 1.0*1000;
    60                     else
    61                         temp = temp;
    62                 }
    63             }
    64             if(flag == 1)
    65             P = temp,flag = 0;
    66             else if(flag == 2)
    67             U = temp,flag = 0;
    68             else if(flag == 3)
    69             I = temp,flag = 0;
    70             else
    71                 flag = flag;
    72         }
    73         printf("Problem #%d\n",r);
    74         if(I == 0)
    75         {
    76             printf("I=%.2lfA\n",P/U);
    77         }
    78         else if(P == 0)
    79         {
    80             printf("P=%.2lfW\n",I*U);
    81         }
    82         else
    83         {
    84             printf("U=%.2lfV\n",P/I);
    85         }
    86         //本来我这个地方加了一句if(r != T)的,意思是最后一行不输出空行,结果就在这个地方,让我错了三次,看来UVA不知考察编码,而且还极大地锻练ACM爱好者的英语水平
    87         printf("\n");
    88     }
    89         return 0;
    90 }
  • 相关阅读:
    scrollview嵌套recyclerview显示不全现象
    scrollview嵌套recyclerview卡顿现象
    设计模式——原型模式
    设计模式——访问者模式
    设计模式——外观模式
    设计模式——责任链模式
    设计模式——组合模式
    设计模式——享元模式
    设计模式——迭代器模式
    设计模式——备忘录模式
  • 原文地址:https://www.cnblogs.com/SDUTYST/p/2525846.html
Copyright © 2011-2022 走看看