UVA - UVA - 537 Artificial

来源:互联网 发布:怎样把nginx部署到公网 编辑:程序博客网 时间:2024/05/01 15:09

UVA - UVA - 537 Artificial Intelligence?

题目大意:给定两个量根据UI=P算第三个量

解题思路:跟据 ‘U=’ ‘I=’ ‘P=’ 读取 数据 需要注意打数 m k M 等单位换算 以及 A W V 需要注意匹配

#include <cstdio>#include <cstring>#include <cstdlib>int main() {    int N;    char a[10005];    scanf("%d",&N);    getchar();    int t = 1,t1,t2,t3;    float s11, s22, s33;    char s1[100],s2[100],s3[100];    while (N--) {        t1 = t2 = t3 = 0;        s11 = s22 = s33 = 1;        memset(a, 0 ,sizeof(a));        memset(s1, 0, sizeof(s1));        memset(s2, 0, sizeof(s2));        memset(s3, 0, sizeof(s3));        gets(a);        for ( int i = 0; i < strlen(a); i++) {            if (a[i] == 'U' && a[i+1] == '=') {                t1 = 1;                 for (int j = 0; a[i+j+2] != 'V'; j++) {                    if ( a[i+j+2] == 'M' )                        s11 = 1000000;                    else if ( a[i+j+2] == 'm')                        s11 = 0.001;                    else if ( a[i+j+2] == 'k')                        s11 = 1000;                    else                     s1[j] = a[i+j+2];                }            }            if (a[i] == 'I' && a[i+1] == '=') {                t2 = 1;                for (int j = 0; a[i+j+2] != 'A'; j++) {                    if ( a[i+j+2] == 'M' )                        s22 = 1000000;                    else if ( a[i+j+2] == 'm')                        s22 = 0.001;                    else if ( a[i+j+2] == 'k')                        s22 = 1000;                    else                    s2[j] = a[i+j+2];                }            }            if (a[i] == 'P' && a[i+1] == '=') {                t3 = 1;                 for (int j = 0; a[i+j+2] != 'W'; j++) {                    if ( a[i+j+2] == 'M' )                        s33 = 1000000;                    else if ( a[i+j+2] == 'm')                        s33 = 0.001;                    else if ( a[i+j+2] == 'k')                        s33 = 1000;                    else                    s3[j] = a[i+j+2];                }            }        }           if (t1 == 1 && t2 == 1)            printf("Problem #%d\nP=%.2lfW\n", t, s11*s22*atof(s1)*atof(s2));        if (t3 == 1 && t2 == 1)            printf("Problem #%d\nU=%.2lfV\n", t, s22*s33*atof(s3)/atof(s2));        if (t1 == 1 && t3 == 1)            printf("Problem #%d\nI=%.2lfA\n", t, s11*s33*atof(s3)/atof(s1));        t++;        printf("\n");    }}
0 0
原创粉丝点击