poj1214(链表

这篇博客主要讲述了作者在解决POJ1214链表题目时遇到的问题,以及在不同在线评测平台如UVA和POJ上的运行体验。作者发现POJ虽然有错误反馈,但运行速度较慢,而UVA则出现超时情况,相比之下,ZOJ的运行效率更高。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

uva的感觉好卡。。去看看poj发现有一样的题目,就在poj上测了,还有错误反馈QAQ不过感觉也是挺卡的,还是zoj流畅。

此题目- -纯练习链表。。。

好吧,,,在poj运行16ms。。为什么在uva就是超了3s- -。。。

#include <iostream>
#include <stack>
#include <string>
using namespace std;

struct lnode
{
    stack<string> poke;
    lnode* fron;
    lnode* next;
};
bool test(string a,string b)
{
    if(a[0] == b[0] || a[1] == b[1])
        return true;
    else return false;
}
bool Find_left3(lnode* top,string po,int m)
{
    lnode* go = top;
    for(int m = 0;m < 2;m++)
    {
        if(go->fron != NULL)
            go = go->fron;
        else break;
        if(m == 1 && test(go->poke.top(),po))
        {
            go->poke.push(po);
            return true;
        }
    }
    return false;
}
bool Find_left3_1(lnode* a,int& num,lnode* &top,int m)
{
    lnode* go = a;
    lnode* left = a;
    for(;m < 3;m++)
    {
        if(left->fron != NULL)
            left = left->fron;
        else break;
        if(m == 2 && test(go->poke.top(),left->poke.top()))
        {
            left->poke.push(go->poke.top());
            go->poke.pop();
            if(go->poke.empty())
            {
                if(top == go)
                    top = top->fron;
                go->fron->next = go->next;
                if(go->next != NULL)
                go->next->fron = go->fron;
                go->fron = go->next = NULL;
                num--;
            }
            return true;
        }
    }
    return false;
}
int main()
{
    string po;
    while(cin >> po && po != "#")
    {
        lnode pokes[52];
        lnode* top = &pokes[0];
        int num = 1;
        pokes[0].poke.push(po);
        pokes[0].next = &pokes[1];
        pokes[0].fron = NULL;
        for(int m = 1;m<52;m++)
        {
            cin >> po;
            if(Find_left3(top,po,0));
            else if(Find_left3(top,po,1));
            else
            {
                num++;
                pokes[m].poke.push(po);
                top->next = &pokes[m];
                pokes[m].fron = top;
                pokes[m].next = NULL;
                top = &pokes[m];
            }
            lnode* go = &pokes[0];
            while(go != NULL)
            {
                if(Find_left3_1(go,num,top,0)) {go = &pokes[0];continue;}
                else if(Find_left3_1(go,num,top,2)) {go = &pokes[0];continue;}
                else
                    go = go->next;
            }
        }
        lnode* go = &pokes[0];
        cout << num << " piles remaining:";
        while(go != NULL)
        {
            cout << ' ' << go->poke.size();
            go = go->next;
        }
        cout << endl;
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值