⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1453.cpp

📁 这是哈尔滨工业大学acmOJ的源代码
💻 CPP
字号:
/*  This Code is Submitted by wywcgs for Problem 1453 on 2005-03-19 at 22:24:40 */ 
#include <stdio.h>

typedef struct{
    int prefixe;
    double value;
}PhysicNum;    

int main()
{
    char ch[2];
    PhysicNum P, U, I;
    double dTemp;
    int i, j, test, flag, prefixe;
    
    scanf("%d", &test);
    while(getchar() != '\n')
        ;
    for(i = 1; i <= test; i++){
        ch[0] = 0;
        flag = 0;
        while((ch[1] = getchar()) != '\n'){
            if(ch[1] == '='){
                scanf("%lf", &dTemp); 
                prefixe = 0;
                ch[1] = getchar();
                if(ch[1] == 'm'){
                    prefixe = -3;
                }else if(ch[1] == 'k'){
                    prefixe = 3;
                }else if(ch[1] == 'M'){
                    prefixe = 6;
                }    
                switch(ch[0]){
                    case 'U':
                        U.value = dTemp;
                        U.prefixe = prefixe;
                        flag += 1;
                        break;
                    case 'I':
                        I.value = dTemp;
                        I.prefixe = prefixe;
                        flag += 2;
                        break;
                    case 'P':
                        P.value = dTemp;
                        P.prefixe = prefixe;
                        flag += 4;
                        break;
                }
            }
            ch[0] = ch[1];
        }
        printf("Problem #%d\n", i);
        if(flag == 3){
            P.value = U.value * I.value;
            P.prefixe = U.prefixe + I.prefixe;
            if(P.prefixe > 0){
                for(j = 0; j < P.prefixe; j++){
                    P.value *= 10;
                }
            }else if(P.prefixe < 0){
                for(j = 0; j < -P.prefixe; j++){
                    P.value /= 10;
                }
            }
            printf("P=%.2lfW\n\n", P.value);
        }else if(flag == 5){
            I.value = P.value / U.value;
            I.prefixe = P.prefixe - U.prefixe;
            if(I.prefixe > 0){
                for(j = 0; j < I.prefixe; j++){
                    I.value *= 10;
                }
            }else if(I.prefixe < 0){
                for(j = 0; j < -I.prefixe; j++){
                    I.value /= 10;
                }
            }
            printf("I=%.2lfA\n\n", I.value);
        }else if(flag == 6){
            U.value = P.value / I.value;
            U.prefixe = P.prefixe - I.prefixe;
            if(U.prefixe > 0){
                for(j = 0; j < U.prefixe; j++){
                    U.value *= 10;
                }
            }else if(U.prefixe < 0){
                for(j = 0; j < -U.prefixe; j++){
                    U.value /= 10;
                }
            }
            printf("U=%.2lfV\n\n", U.value);
        }
    }
    
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -