uva 101

uva 老是打不开,代码没有提交成功。但应该是对的。。。
一道模拟题,用vector做的。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

const int maxn = 26;
int n;
vector<int> stat[maxn];

void moveback(int id){
    int i,j,mark,len;
    for(i=0;i<n;i++){
        for(j=0;j<stat[i].size();j++){
            if(stat[i][j] == id) {
                mark = i;
                len = j;
                break;
            }
        }
    }
    for(i=stat[mark].size()-1;i>len;i--){
        stat[stat[mark][i]].push_back(stat[mark][i]);
        stat[mark].pop_back();
    }
}
void putonto(int a ,int b){
    int i,j,mark1,mark2;
    for(i=0;i<n;i++){
        for(j=0;j<stat[i].size();j++){
            if(stat[i][j] == a)  mark1 = i;
            if(stat[i][j] == b)  mark2 = i;
        }
    }
    if(mark1 == mark2) return;
    stat[mark2].push_back(a);
    stat[mark1].pop_back();
}

void putover(int a,int b){
    int i,j,mark1,mark2,len;
    for(i=0;i<n;i++){
        for(j=0;j<stat[i].size();j++){
            if(stat[i][j] == a) {mark1 = i;len = j;}
            if(stat[i][j] == b)  mark2 = i;
        }
    }
    if(mark1 == mark2) return;
    int marksize = stat[mark1].size();
    for(i=len;i< marksize ;i++){
        stat[mark2].push_back(stat[mark1][i]);
    }
    for(i=len;i< marksize ;i++){
        stat[mark1].pop_back();
    }
}

void print(){
    int i,j,mark1,mark2;
    for(i=0;i<n;i++){
        cout<<i<<":";
        for(j=0;j<stat[i].size();j++){
            cout<<stat[i][j]<<" ";
        }
        cout<<endl;
    }
}

int main(){
    int i,j,a,b;
    string cmd;
    string cr;
    for(i=0;i<maxn;i++){
        stat[i].push_back(i);
    }
    scanf("%d",&n);
    while(cin>>cmd){
        if(cmd == "quit") break;
        else{
        cin>>a>>cr>>b;
        if(cmd == "move"){
            moveback(a);
            if(cr == "onto"){
                moveback(b);
                putonto(a,b);
            } 
            else if(cr == "over"){
                putonto(a,b);
            }
            else continue;
        }
        else if(cmd == "pile"){
            if(cr == "onto"){
                moveback(b);
                putover(a,b);
            } 
            else if(cr == "over"){
                putover(a,b);
            }
            else continue;
        }
        else continue;
        }
        //print();
    }
    print();

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值