中南大学2018年ACM暑期集训前期训练题集(入门题) Q: Simple Line Editor
2024-10-20 05:27:17
数据有毒,一个一个读字符是错,整个字符串读入,一次就A了。
总之,数据总是没有错的,还是对c++了解地不够深刻,还有,在比赛中,一定要有勇气重构代码
错误代码:
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
int T,t;
scanf("%d",&T);
char a[1024];
getchar();
while(T--){
t=0;a[0]=0;
char c;
while(scanf("%c",&c)!=EOF){
if(c==10){printf("%s\n",a);break;}
if(c=='#'){t=max(0,--t);}
else if(c=='@'){t=0;a[t]=0;}
else {
a[t]=c;a[++t]=0;
}
}
}
}
AC代码:
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char a[1024];
char ans[1024];
int T;
cin>>T;
while(T--){
cin>>a;
int n=strlen(a);int t=0;
for(int i=0;i<n;i++){
if(a[i]=='#'){t=max(0,--t);}
else if(a[i]=='@'){t=0;}
else {
ans[t++]=a[i];
}
}
ans[t]=0;
cout<<ans<<endl;
}
}
最新文章
- Atitit.log日志技术的最佳实践attilax总结
- 【Cocos2d-x游戏开发】细数Cocos2d-x开发中那些常用的C++11知识
- 20160620001 FileUpload控件获取上传文件的路径
- win7刷新图标缓存
- 【 D3.js 高级系列 — 1.0 】 文本的换行
- WPF 中,动态创建Button,并使Button得样式按照自定义的Resource样式显示
- jQuery HTML CSS 方法
- 利用MVC的过滤器实现url的参数加密和解密
- 【递推】地铁重组(subway) 解题报告
- IFTT-意大利金融交易税
- tomcat解析之简单web服务器(图)
- GWT开端
- css3hover效果
- struts2和spring mvc的比较
- 502 VS 504
- [SCOI2010]幸运数字 [容斥原理 dfs]
- Python Web-第四周-Programs that Surf the Web(Using Python to Access Web Data)
- 深入分析synchronized的实现原理
- 关于读取mapper的两种方式
- Ubuntu上Qt之简单图片浏览器