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:怎么算是输入结束,C++怎么写?

Posted by Scidets at 2011-09-05 20:27:40 on Problem 2577
In Reply To:怎么算是输入结束,C++怎么写? Posted by:Scidets at 2011-09-05 19:35:39
> RET
还有,Runtime Error会是什么原因?请大牛们指教,下面是我的代码
#include <iostream>

using namespace std;

class Interpreter
{
public:
    int *store;
    int reg[10]; //寄存器
    int d,n;
    int op;
    int step;

public:
    void init(){
        store = new int[1000];
    }

    void del(){
        delete(store);
    }

    int cal(int op,int d,int n)
    {
        int flag=-1;

        switch (op)
        {
        case 2:
        {
            reg[d]=n;
        }
        ;
        break;
        case 3:
        {
            reg[d] = (reg[d]+n)%1000;
        }
        ;
        break;
        case 4:
        {
            reg[d] = (reg[d]*n)%1000;
        }
        ;
        break;
        case 5:
        {
            reg[d]=reg[n];
        }
        ;
        break;
        case 6:
        {
            reg[d]= (reg[d]+reg[n])%1000;
        }
        ;
        break;
        case 7:
        {
            reg[d]= (reg[d]*reg[n])%1000;
        }
        ;
        break;
        case 8:
        {
            reg[d]=store[n];
        }
        ;
        break;
        case 9:
        {
            store[n] = reg[d];
        }
        ;
        break;
        case 0:
        {
            if (reg[n]!=0)
            {
                flag=reg[d]-1;
            }
        }
        ;
        break;
        default:
            //cout<<"error input"<<endl;
            break;
        }

        return flag;
    }

    };

int main()
{
    Interpreter ip;
    int j;
    int ret, flag;
    int d, n, op;

            ip.init();

            flag = 0;

            j=0;
            while(cin>>ip.store[j])
            j++;

            for(j=0;j<10;j++)ip.reg[j]=0;

            j=0;

            ip.step = 1;
            while(ip.store[j]!=100)
            {
                ip.step++;
                op = ip.store[j]/100;
                d = ip.store[j]%100/10;
                n = ip.store[j]%10;

                ret=ip.cal(op,d,n);

                if (ret!=-1)
                {
                    j = ret;
                }

                j++;
            }

            cout<<ip.step<<endl;

            ip.del();
    return 0;
}

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