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 可方便地处理这样以行为界定的输入数据
相关文章推荐
- C#模拟http 发送post或get请求的简单实例
- Transformation 能将 Windows XP/Server 2003 操作系统,完美地模拟成 Windows Vista 的软件
- 用javascript和css模拟select的脚本
- PHP模拟asp.net的StringBuilder类实现方法
- C#使用ImitateLogin模拟登录百度
- javascript用层模拟可移动的小窗口
- JS模拟简易滚动条效果代码(附demo源码)
- 自编jQuery插件实现模拟alert和confirm
- JS模拟按钮点击功能的方法
- PHP模拟asp中response类实现方法
- 模拟Spring的简单实现
- javascript 模拟点击广告
- JQuery中模拟image的ajaxPrefilter与ajaxTransport处理
- php实现模拟post请求用法实例
- JavaScript实现MIPS乘法模拟的方法
- 模拟xcopy的函数
- JS模拟实现Select效果代码
- php模拟服务器实现autoindex效果的方法
- C# SendInput 模拟鼠标操作的实现方法
- PHP模拟登陆163邮箱发邮件及获取通讯录列表的方法