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

大家帮下忙啊,罕见的RE啊,我找半天错误找不出来啊

Posted by yk000123 at 2009-11-13 13:21:06 on Problem 2121
#include <iostream>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

map< string, int> mm;

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

int calc(string *pl, string *pr)
{
    int ret=0;
    string *p=find(pl,pr,key[29]);
    if (p!=pr) {
        ret+=mm[*(p-1)]*val[29];
        pl=p+1;
    }
    while (pl!=pr) {
        ret+=mm[*pl];
        ++pl;
    }
    return ret;
}

int main()
{
    for (int i=0; i<32; ++i)
        mm[key[i]]=val[i];
    string s;
    while (getline(cin,s)) {
        stringstream sin(s);
        int r=0;
        while (sin>>a[r]) ++r;
        int l=0, sign=1;
        if (a[0]==key[0]) { sign=-1; l=1; }
        int ans=0; string *p;
        if ( ( p = find(a+l,a+r,key[31]) ) !=a+r ) {
            ans+=calc(a+l,p)*val[31];
            l=p-a+1;
        }
        if ( ( p = find(a+l,a+r,key[30]) ) !=a+r ) {
            ans+=calc(a+l,p)*val[30];
            l=p-a+1;
        }
        ans+=calc(a+l,a+r);
        ans*=sign;
        cout<<ans<<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