溢出???

P2830 写程序

zhangfengkai001 @ 2024-10-04 23:06:51

#include <iostream>
#include <string>
#include <map>

using namespace std;

const string in = "int";
const string put = "cout";

map<string, int> dmp;
int dd = 0;
int ddmp[100][1000000];
int dds[100];

struct ddrt
{
    int v;
    bool yc;
};

inline int makd(string s)
{
    short l = s.size();
    int px = 1;
    int turn = 0;
    for (int i = l - 1; i >= 0; i--)
    {
        turn += (s[i] - '0') * px;
        px *= 10;
    }
    return px; 
}

int trds(string s)
{ 
    string ddnr = "";
    int nzb;
    for (int i = 0;; i++)
    {
        if (s[i] == '[')
        {
            nzb = i + 1;
            break;
        }
        ddnr += s[i];
    }
    string dddr = "";
    int ddh = dmp[ddnr];
    for (int i = nzb; i < s.size(); i++)
    {
        if (s[i] != ']')
        {
            if (dddr[i - 1] <= '9' && dddr[i - 1] >= '0')
            {
                int mdd = makd(dddr);

                if (dds[ddh] < mdd)
                {
                    cout << "-1";
                    exit(0);
                }
                return ddmp[ddh][makd(dddr)];
            }
            break;
        }
        else
        {
            return trds(dddr);
        }
        dddr += s[i];
    }
}

void putdindex(string s, int v)
{
    string ddnr = "";
    int nzb;
    for (int i = 0;; i++)
    {
        if (s[i] == '[')
        {
            nzb = i + 1;
            break;
        }
        ddnr += s[i];
    }
    string dddr = "";
    int ddh = dmp[ddnr];
    for (int i = nzb; i < s.size(); i++)
    {
        if (s[i] != ']')
        {
            if (dddr[i - 1] <= '9' && dddr[i - 1] >= '0')
            {
                int mdd = makd(dddr);

                if (dds[ddh] < mdd)
                {
                    cout << "-1";
                    exit(0);
                }
                ddmp[ddh][makd(dddr)] = v;
                return;
            }
            break;
        }
        else
        {
            putdindex(dddr,v);
        }
        dddr += s[i];
    }
}

int main()
{
    string kw;
    string nw;
    while (cin >> kw)
    {
        cin >> nw;
        if (kw == in)
        {
            cout<<"I read int.";
            string dn;
            string ds;
            short lon;
            for (int i = 0; i < nw.size(); i++)
            {
                if (nw[i] != '[')
                {
                    dn += nw[i];
                }
                else
                {
                    lon = i;
                    break;
                }
            }
            dmp[dn] = dd++;
            for (int i = lon; i < nw.size(); i++)
            {
                if (nw[i] != ']')
                {
                    ds += nw[i];
                }
                else
                {
                    dds[dmp[dn]] = trds(ds);
                }
            }
        }
        else if (kw == put)
        {
            int v= trds(nw);
            cout << v << '\n';
        }
        else
        {
            putdindex(kw, trds(nw));
        }
    }
    return 0;
}

看看吧,有用送《渡口》无损音源!!!


by cjy100 @ 2024-10-06 11:05:28

@zhangfengkai001 你的trds函数是什么


by zhaoyiling2023 @ 2024-10-06 12:08:33

@zhangfengkai001 zfk你变了!你竟然会伤心!


上一页 |