Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

这组数据都试过了,还是WA,谁帮着看看?

Posted by thinkinnight at 2007-06-05 13:25:20 on Problem 2121
In Reply To:这组数据都过了 应该就可以过了 Posted by:gengyit at 2007-05-27 13:57:46
#include <iostream>
#include <string>
using namespace std;

struct nums
{
    int num;
    char str[20];
};

nums nu[] = {
    {0,"zero"}, {1,"one"}, {2,"two"},
    {3,"three"}, {4,"four"}, {5,"five"},
    {6,"six"}, {7,"seven"}, {8,"eight"},
    {9,"nine"}, {10,"ten"}, {11,"eleven"},
    {12,"twelve"}, {13,"thirteen"}, {14,"fourteen"},
    {15,"fifteen"}, {16,"sixteen"}, {17,"seventeen"},
    {18,"eighteen"}, {19,"nineteen"}, {20,"twenty"},
    {30,"thirty"}, {40,"forty"}, {50,"fifty"},
    {60,"sixty"}, {70,"seventy"}, {80,"eighty"},
    {90,"ninety"},
    {-1,"negative"},
    {100,"hundred"},
    {1000,"thousand"},
    {1000000,"million"}
};

int main()
{
    char input[200];
    while(cin.getline(input,200))
    {
        string str = input;
        int result = 0;
        int calc = 0;
        int mill = 0;
        int th = 0;
        bool b_na = false;
        bool b_hun = false;
        size_t pos=0,pos2=0;
        str += " ";
        while((pos2=str.find(" ",pos))!=string::npos)
        {
            string calcstr = str.substr(pos,pos2-pos);
            pos = pos2+1;
            if(calcstr.compare(nu[28].str)==0)
            {
                b_na = true;
                continue;
            }

            for(int i=0;i<32;i++)
            {
                if(calcstr.compare(nu[i].str)==0)
                {
                    if(i==31)
                    {
                        mill = calc*nu[i].num;
                        calc=0;
                    }
                    else if(i==29)
                    {
                        b_hun=true;
                        calc *= nu[i].num;
                    }
                    else if(i==30)
                    {
                        if(b_hun)
                        {
                            th = calc*nu[i].num;
                            calc = 0;
                        }
                        else
                            calc*=nu[i].num;
                    }
                    else
                        calc += nu[i].num;
                }
            }
        }

        result = mill+th+calc;

        if(b_na)
            result *= -1;
        cout<<result<<endl;
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator