zoukankan      html  css  js  c++  java
  • uva-11111-栈

    注意输入和输出的结果

    -9 -7 -2 2 -3 -2 -1 1 2 3 7 9
    -9 -7 -2 2 -3 -1 -2 2 1 3 7 9
    -9 -7 -2 2 -3 -1 -2 3 2 1 7 9
    -100 -50 -6 6 50 100
    -100 -50 -6 6 45 100
    -10 -5 -2 2 5 -4 -3 3 4 10
    -9 -5 -2 2 5 -4 -3 3 4 9
    -10 -5 -3 3 -1 1 5 -4 4 10

    10
    -10 10

    -10

    :-) Matrioshka!
    :-( Try again.
    :-( Try again.
    :-) Matrioshka!
    :-( Try again.
    :-) Matrioshka!
    :-( Try again.
    :-) Matrioshka!
    :-( Try again.
    :-) Matrioshka!
    :-( Try again.

    #include <iostream>
    #include <sstream>
    #include<memory.h>
    #include<stdio.h>
    using namespace std;
    const int N = 10000;
    struct stack
    {
        int a[N];
        int index;
        stack()
        {
            index = 0;
        }
        void push(int i)
        {
            a[index++] = i;
        }
        int pop()
        {
            int i = a[--index];
            return i;
        }
    };
    int main()
    {
        int n;
        string str;
        while (getline(cin, str))
        {
            istringstream is(str);
            int hasInt = 0;
            stack s;
            memset(s.a, 0, sizeof(s.a));
            int error = 0;
            while (is >> n)
            {
                hasInt++;
                if (n < 0)
                    s.push(n);
                else
                {
                    int t = 0;
                    while (s.index)
                    {
                        int j = s.pop();
                        if (j > 0)
                            t += j;
                        else
                        {
                            if (j != n * -1)
                                error = 1;
                            break;
                        }
                    }
                    if (t < n && !error)
                        s.push(n);
                    else
                        break;
                }
            }
            if (!hasInt)
            {
                //cout << ":-( Try again." << endl;
                continue;
            }
            if (hasInt == 1)
            {
                cout << ":-( Try again." << endl;
                continue;
            }
            if (error || s.index != 1)
                cout << ":-( Try again." << endl;
            else if (s.index == 1)
            {
                if (s.pop() > 0)
                    cout << ":-) Matrioshka!" << endl;
                else
                    cout << ":-( Try again." << endl;
            }
        }
        return 0;
    }
  • 相关阅读:
    MM-RGV、AGV 、IGV是什么
    WDA-FPM-4-用OVP做查询跳转到明细
    WDA-FPM-3-SEARCH(OIF)
    WDA-FPM-2-APPLICATION-TABSTRIP(OIF)
    WDA-FPM-1-Roadmap(GAF)
    WDA-BOPF业务对象处理框架
    WDA-WebDynpro Demo & FPM Demo
    WDA-参考路径
    MM-库存表
    洗礼灵魂,修炼python(12)--python关键词,包
  • 原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/7345754.html
Copyright © 2011-2022 走看看