What is artificial intelligence?

Source: Internet
Author: User

Question link: http://uva.onlinejudge.org/index.php? Option = com_onlinejudge & Itemid = 8 & page = show_problem & problem = 478

Question: It's really frustrating. This question has been done for a long time. The meaning of tat is very simple. It is to describe any two of the voltage U current I power P in a language and find another one.

String Conversion and unit judgment. It's not difficult. It's always in WA. It's just because the header file uses cstdio, and stdio. h is used to restore to normal. It's really, it's just !!!!

Code:

#include <iostream>#include <stdio.h>using namespace std;char s[1000];char *getnum(char *p,double &ans){    ans = 0;    while(*p >= '0' && *p <= '9')    {        ans = *p - '0' + ans * 10;        p++;    }    if(*p == '.')    {        p++;        double quan = 0.1;        while(*p >= '0' && *p <= '9')        {            ans = ans + quan * (*p - '0');            quan *= 0.1;            p++;        }    }    return p;}int main(){    int N;    cin >> N;    cin.get();    double u,i,ap;    bool bu,bi,bp;    int no = 1;    while(N--)    {        cin.getline(s,1000);        char *p = s;        bu = 0;        bi = 0;        bp = 0;        while(*p != '\0')        {            if(*p == '=')            {                if(*(p - 1) == 'u' || *(p - 1) == 'U')                {                    bu = 1;                    p++;                    if(*p >= '0' && *p <= '9')                        p = getnum(p,u);                    if(*p == 'm')                        u *= 0.001;                    if(*p == 'k')                        u *= 1000;                    if(*p == 'M')                        u *= 1000000;                }else if(*(p - 1) == 'i' || *(p - 1) == 'I')                {                    bi = 1;                    p++;                    if(*p >= '0' && *p <= '9')                        p = getnum(p,i);                    if(*p == 'm')                        i *= 0.001;                    if(*p == 'k')                        i *= 1000;                    if(*p == 'M')                        i *= 1000000;                }else if(*(p - 1) == 'p' || *(p - 1) == 'P')                {                    bp = 1;                    p++;                    if(*p >= '0' && *p <= '9')                        p = getnum(p,ap);                    if(*p == 'm')                        ap *= 0.001;                    if(*p == 'k')                        ap *= 1000;                    if(*p == 'M')                        ap *= 1000000;                }            }            p++;        }        cout << "Problem #" << no++ << endl;        if(bu && bi)            printf("P=%.2lfW\n",u * i);        else if(bp && bi)            printf("U=%.2lfV\n",ap / i);        else if(bu && bp)            printf("I=%.2lfA\n",ap / u);        cout << endl;    }    return 0;}
Dream code: http://www.hypo.xyz

What is artificial intelligence?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.