sdut 3567 Memory Leak 模拟
来源:互联网 发布:识汝不识丁网络剧资源 编辑:程序博客网 时间:2024/06/05 02:55
题意:
模拟c++的输入,如果输入的字符串大于声明的空间就会寻找下一个字符串直到找到'\0'
坑点:gets name 的第一个空格后都是输入的内容
ACcode:
#include <bits/stdc++.h>using namespace std;#define maxn 11111string name[maxn];int len1[maxn],len2[maxn];char tmp[maxn];map<string ,int>vis;int main(){ int loop; scanf("%d",&loop); while(loop--){ scanf("%s",tmp); vis.clear(); memset(len1,0,sizeof(len1)); memset(len2,0,sizeof(len2)); for(int i=0;i<maxn;++i)name[i]=""; int tot=1; while(1){ scanf("%s",tmp); int len=strlen(tmp); name[tot]=""; bool flag=true; int k; for(k=0;flag&&k<len;++k){ if(tmp[k]!='[') name[tot]+=tmp[k]; else flag=false; } len1[tot]=0; flag=true; for(;flag&&k<len;++k) if(isdigit(tmp[k])) len1[tot]=len1[tot]*10+tmp[k]-'0'; else flag=false; vis[name[tot]]=tot; if(tmp[k]==';')break; tot++; } while(scanf("%s",tmp)&&tmp[0]!='r'){ if(tmp[0]=='g'){ scanf("%s",tmp); int pos=vis[tmp]; gets(tmp); int ll=strlen(tmp); name[pos]=""; int k=1,lll=0; for(lll=0;k<ll;++k,++lll) name[pos]+=tmp[k]; name[pos][lll]='\0'; len2[pos]=lll; }else { scanf("%s",tmp); int pos=vis[tmp]; if(len2[pos]==0)cout<<'\12'; else{ if(len1[pos]>len2[pos]) cout<<name[pos]<<'\12'; else { for(int i=0;i<len1[pos];++i)cout<<name[pos][i]; int k=pos+1; while(len1[k]<=len2[k]&&len2[k]>0){ for(int i=0;i<len1[k];++i)cout<<name[k][i]; k++; } if(len2[k]) cout<<name[k]<<'\12'; else cout<<'\12'; } } } } scanf("%s",tmp); } return 0;}/*1char a[2], b[1], c[1], d[111];gets a 1gets b 2c agets a 11c agets c 33c agets b 22c ac breturn 0;4char a[1], b[1], c[12];gets a 123cout areturn 0;char a[1], b[2], c[12];gets a 123cout agets b 123cout acout bgets b 12cout acout bretrun 0;char a[1], b[2], c[12];gets a 12345gets c 12cout agets b 12cout acout bcout creturn 0;char a[1], b[2], c[12];gets a 12345gets c 12cout agets b 1cout acout bcout creturn 0;*/
0 0
- sdut 3567 Memory Leak 模拟
- Memory Leak
- memory leak
- Memory leak
- 第七届山东省ACM省赛 H Memory Leak 模拟
- 第七届 山东省ACM Memory Leak(模拟 待整理)
- sdut 3567 模拟
- detect memory leak macro
- detect memory leak macro
- Enabling Memory Leak Detection
- memory leak( 纯属备份)
- Pixbuf causes memory leak
- solaris memory leak
- Memory Leak分析分享
- memory leak in occi
- Detecting Memory Leak
- Memory leak finder
- java Memory Leak
- Spring并发访问的线程安全性问题(高度总结)
- 【学习笔记】mysql查询优化器的局限性
- 微软SQLHelper
- Java回调函数使用
- git使用笔记-分支
- sdut 3567 Memory Leak 模拟
- 清除微信浏览器缓存问题
- poj2418 Map统计单词数
- VC++中的字体设置方法详解
- 【CRM】01- WEB UI 下拉列表
- IIC协议
- Unity 3D
- WindowManager.LayoutParams详解总结和对应实例
- 哈密顿图 poj 1776