[Login|Register]
New post

Show post

Search forum

Read post
哪个提交成功的高手看下为何wrong answer? [ Topic ] 2010-01-31 19:33:49 qykg
#include<iostream>
#include<string>
const int MAX=7;
using namespace std;
int main()
{
    string a;
    int n[MAX];
    int k=0;
    int N[MAX];
    int sum1,sum2;
    while(cin>>a)
    {    
        k=0;
        for(int x1=0;x1<MAX;x1++)
        {
            n[x1]=0;
            N[x1]=0;
        }
        for(int i=0;i<a.length();i++)
        {
            if(a[i]=='+'||a[i]=='-'||a[i]=='*'||a[i]=='/')
            {
                k++;
                n[k]=i;        
            }
        }
        if(n[1]==2)
            N[1]=10*(a[0]-48)+(a[1]-48);
        else if(n[1]==1)
            N[1]=a[0]-48;
        for(int j=2;j<=k;j++)
        {
            if(n[j]-n[j-1]==3)
                N[j]=(a[n[j]-2]-48)*10+(a[n[j]-1]-48);
            else if(n[j]-n[j-1]==2)
                N[j]=a[n[j]-1]-48;
        }
        if(a.length()-1-n[k]==2)
            N[k+1]=(a[n[k]+1]-48)*10+(a[n[k]+2]-48);
        else if(a.length()-1-n[k]==1)
            N[k+1]=a[n[k]+1]-48;
        for(int x=1;x<=k;x++)
        {
            if(a[n[x]]=='*')
            {        
                N[x+1]=N[x]*N[x+1];
                N[x]=0;
                if(a[n[x-1]]=='+')
                    a[n[x]]='+';
                else if(a[n[x-1]]=='-')
                    a[n[x]]='-';
            }
            else if(a[n[x]]=='/')
            {
                N[x+1]=N[x]/N[x+1];
                N[x]=0;
                if(a[n[x-1]]=='+')
                    a[n[x]]='+';
                else if(a[n[x-1]]=='-')
                    a[n[x]]='-';
            }
        }
        sum1=N[1];
        sum2=0;
        for(int k2=1;k2<k+1;k2++)
        {
            if(a[n[k2]]=='+')
                sum1+=N[k2+1];
            else
                sum2+=N[k2+1];
        }
        cout<<sum1-sum2<<endl;
    }
    return 0;
}
真的很想知道为什么??
Reply
Title
Message
(64K)
University of Science and Technology of China
Online Judge for ACM/ICPC
Processed in 2.8ms with 2 query(s).