您的位置:首页 > 其它

2016山东省赛H题

2016-06-09 08:41 309 查看
/*************************************************************************
> File Name: 山东H.cpp
> Author:HaoWei
> Mail:liang199611@outlook.com
> Created Time: 2016年06月07日 星期二 16时20分50秒
************************************************************************/

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<string>
#include<map>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
const int maxn=11111;
stringstream ss;
string tempLine;
char total[maxn];
int topOfArray;
map<string,int> M;

void init()
{
ss.clear();
if(ss.sync()==-1) cout<<"wrong"<<endl;
M.clear();
topOfArray=0;
total[topOfArray]='\0';
}
int main()
{
freopen("山东H.in","r",stdin);
while(getline(cin,tempLine))
{
ss.clear();if(ss.sync()==-1) cout<<"wrong"<<endl;

ss<<tempLine;
// cout<<tempLine<<endl;
string op,name;ss>>op;
// cout<<op<<endl;
if(op[0]=='r') {string temp;ss>>temp;init();continue;}
if(op[0]=='c'&&op[1]=='h') {
while(true)
{
ss.ignore();//忽略空格

getline(ss,name,'[');
//  cout<<name<<endl;
int len;ss>>len;//读取数字
//    cout<<len<<endl;

ss.ignore();//忽略']'

M[name]=topOfArray;topOfArray+=len;

char dilima;ss>>dilima;
//      cout<<dilima<<endl;
if(dilima==';') break;
else{}//忽略'逗号'
}
}
if(op[0]=='c'&&op[1]=='o'){
ss>>name;
// cout<<name<<endl;
printf("%s\n",M[name]+total);
}
if(op[0]=='g'){
ss>>name;
ss.ignore();//忽略空格
string content;getline(ss,content);
//   cout<<content<<endl;
strcpy(total+M[name],content.c_str());
}
}
//for(int i=0;i<maxn;i++) putchar(total[i]);
return 0;
}

题意:模拟strcpy

用streamstring 可方便地处理这样以行为界定的输入数据
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  模拟