• 537 Artificial Intelligence?


    C++语言: Codee#25706
    001 /*
    002 +++++++++++++++++++++++++++++++++++++++
    003                 author: chm
    004 +++++++++++++++++++++++++++++++++++++++
    005 */
    006
    007
    008 #include <map>
    009 #include <set>
    010 #include <list>
    011 #include <queue>
    012 #include <cmath>
    013 #include <stack>
    014 #include <bitset>
    015 #include <cstdio>
    016 #include <cctype>
    017 #include <vector>
    018 #include <cstdlib>
    019 #include <cstring>
    020 #include <fstream>
    021 #include <sstream>
    022 #include <iomanip>
    023 #include <iostream>
    024 #include <algorithm>
    025
    026 using namespace std;
    027
    028 FILE*            fin         = stdin;
    029 FILE*            fout         = stdout;
    030 const int        max_size     = 10086;
    031
    032 double run(char* str, double& prefix)
    033 {
    034     char* pend;
    035     double p = strtod(str, &pend);
    036
    037     if(*pend == 'm')
    038         prefix = 0.001;
    039     else if( *pend == 'M')
    040         prefix = 1000000;
    041     else if(*pend == 'k')
    042         prefix = 1000;
    043     return p;
    044 }
    045
    046 int main()
    047 {
    048 #ifndef ONLINE_JUDGE
    049     freopen("c:\\in.txt", "r", stdin);
    050     fout = fopen("c:\\garage\\out.txt", "w");
    051 #endif
    052
    053     /*
    054        search P U I
    055        get prefix
    056        use formular
    057        */
    058     char str[max_size];
    059     int n;
    060     char* ptrp;
    061     char* ptru;
    062     char* ptri;
    063     double prefixp;
    064     double prefixu;
    065     double prefixi;
    066     double p, u, i;
    067
    068     scanf("%d\n", &n);
    069     for(int j = 1; j <= n; ++j)
    070     {
    071         fgets(str, sizeof(str), stdin);
    072         ptrp = strstr(str, "P=");
    073         ptru = strstr(str, "U=");
    074         ptri = strstr(str, "I=");
    075         prefixp = prefixu = prefixi = 1.0;
    076         fprintf(fout, "Problem #%d\n", j);
    077         if(ptrp)
    078         {
    079             p = run(ptrp + 2, prefixp);
    080             if(ptru)    // i = p / u
    081             {
    082                 u = run(ptru + 2, prefixu);
    083                 fprintf(fout, "I=%.2lfA\n\n", (prefixp / prefixu)* p / u);
    084             }
    085             else        // u = p / i
    086             {
    087                 i = run(ptri + 2, prefixi);
    088                 fprintf(fout, "U=%.2lfV\n\n",  (prefixp / prefixi) * p / i);
    089             }
    090         }
    091         else            // p = u * i
    092         {
    093             u = run(ptru + 2, prefixu);
    094             i = run(ptri + 2, prefixi);
    095             fprintf(fout, "P=%.2lfW\n\n", i * u * prefixi  * prefixu);
    096         }
    097     }
    098
    099 #ifndef ONLINE_JUDGE
    100     fclose(fout);
    101     system("c:\\garage\\check.exe");
    102 #endif
    103     return 0;
    104 }
  • 相关阅读:
    Linux 文本处理工具
    which, whereis, locate, find
    Linux source
    Linux 环境变量
    Linux shell
    spring通过在web.xml中配置ContextLoaderListener来加载spring context配置文件和在DispatcherServlet中也可以来加载spring context配置文件,有什么区别?
    JAVA在线学习优质网站
    java实现AES加解密
    Mybatis Puls @Select() 查询结果映射为Map为null的坑
    springboot自带maven插件打包的jar可以被别的springboot项目引用但不能正确使用
  • 原文地址:https://www.cnblogs.com/invisible/p/2375076.html
Copyright © 2020-2023  润新知