zoukankan      html  css  js  c++  java
  • Artificial Intelligence

    读取题目要求格式的字符串是个问题。

     1 /* UVa 537 - Artificial Intelligence? */
    2 # include <stdio.h>
    3 # include <ctype.h>
    4 # include <stdlib.h>
    5
    6 typedef struct {
    7 double val;
    8 int vis;
    9 }phy;
    10
    11 phy U, I, P, x;
    12 int T;
    13 char tmp[50];
    14
    15 void getval(void);
    16
    17 int main()
    18 {
    19 int i, c, t, j;
    20
    21 scanf("%d", &T);
    22 getchar();
    23 for (i = 1; i <= T; ++i)
    24 {
    25 U.vis = I.vis = P.vis = 0;
    26 printf("Problem #%d\n", i);
    27
    28 getval();
    29
    30 if (!U.vis) printf("U=%.2lfV\n", (P.val)/(I.val));
    31 else if (!I.vis) printf("I=%.2lfA\n", (P.val)/(U.val));
    32 else printf("P=%.2lfW\n", (U.val)*(I.val));
    33
    34 printf("\n");
    35 }
    36 return 0;
    37 }
    38
    39 void getval(void)
    40 {
    41 int j, c, t;
    42 phy x;
    43
    44 while ((c = getchar()) != EOF)
    45 {
    46 if (c == '\n') return ;
    47 if (c == '=')
    48 {
    49 j = 0;
    50 while (isdigit(c = getchar()) || c == '.')
    51 tmp[j++] = c;
    52 tmp[j] = '\0';
    53
    54 x.val = atof(tmp);
    55 if (c == 'm') x.val /= 1000;
    56 else if (c == 'k') x.val *= 1000;
    57 else if (c == 'M') x.val *= 1000000;
    58
    59 x.vis = 1;
    60 if (t == 'U') U = x;
    61 else if (t == 'I') I = x;
    62 else P = x;
    63 }
    64 t = c;
    65 }
    66 }

    一次 AC,加油!

  • 相关阅读:
    erl_0012 timer:tc 测试模块函数调用运行耗时
    erl_0011 erlang 定时器相关
    erl0010
    erl0009
    erl0008
    erl0007
    erl0006
    erl0005
    开开心心过生活、踏踏实实做技术
    Android-理解Intent
  • 原文地址:https://www.cnblogs.com/JMDWQ/p/2400098.html
Copyright © 2011-2022 走看看