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;
}