zcmu-2018:Memory leak

Description

 

Input

 

Output

 对于每种操作输出相应内容

 

Sample Input

3 char a[5], b[5], c[5]; gets a C++ gets b Hello, world! gets c guys cout a cout b cout c return 0; char a[5]; cout a gets a 233 gets a 2333 cout a gets a 12345 cout a return 0; char str1[7], str2[2], str3[5]; gets str1 welcome gets str2 to gets str3 Shandong cout str1 return 0;

Sample Output

C++ Helloguys guys 2333 12345 welcometoShand

模拟题,也没什么好说的,除了非常繁琐以外挺好的。

#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof a);
typedef long long ll;
const int maxn=11000;
map<string,int>b;
struct node
{
    string s,e;
    int l,f;
} a[maxn];
int main()
{
    int t,i,k,v,n;
    char s[11000],x[80],c[9];
    string z;
    scanf("%d",&t);
    while(t--)
    {
        b.clear();
        n=1;
        while(~scanf("%s",c)&&c[0]!='r')
            if(c[1]=='h')
            {
                gets(s);
                stringstream S(s);
                while(S>>z)
                {
                    sscanf(z.c_str(),"%[^[][%d",x,&v);
                    a[n].s=x;
                    a[n].l=v;
                    a[n].e[0]=a[n].f=0;
                    b[x]=n++;
                }
            }
            else if(c[0]=='g')
            {
                scanf("%s",x);
                getchar();
                gets(s);
                a[b[x]].e=s;
                if(strlen(s)<a[b[x]].l)
                    a[b[x]].f=0;
                else
                {
                    a[b[x]].f=1;
                    a[b[x]].e[a[b[x]].l]=0;
                }
            }
            else
            {
                scanf("%s",x);
                i=b[x];
                do
                {
                    printf("%s",a[i].e.c_str());
                }
                while(a[i++].f&&i<n);
                puts("");
            }
        scanf("%s",x);
    }
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值