数据有毒,一个一个读字符是错,整个字符串读入,一次就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;
}
}

  

最新文章

  1. Atitit.log日志技术的最佳实践attilax总结
  2. 【Cocos2d-x游戏开发】细数Cocos2d-x开发中那些常用的C++11知识
  3. 20160620001 FileUpload控件获取上传文件的路径
  4. win7刷新图标缓存
  5. 【 D3.js 高级系列 — 1.0 】 文本的换行
  6. WPF 中,动态创建Button,并使Button得样式按照自定义的Resource样式显示
  7. jQuery HTML CSS 方法
  8. 利用MVC的过滤器实现url的参数加密和解密
  9. 【递推】地铁重组(subway) 解题报告
  10. IFTT-意大利金融交易税
  11. tomcat解析之简单web服务器(图)
  12. GWT开端
  13. css3hover效果
  14. struts2和spring mvc的比较
  15. 502 VS 504
  16. [SCOI2010]幸运数字 [容斥原理 dfs]
  17. Python Web-第四周-Programs that Surf the Web(Using Python to Access Web Data)
  18. 深入分析synchronized的实现原理
  19. 关于读取mapper的两种方式
  20. Ubuntu上Qt之简单图片浏览器

热门文章

  1. 6大爱上react 的理由
  2. Notes of Daily Scrum Meeting(12.23)
  3. Linux 第七周实验 及总结
  4. &lt;&lt;浪潮之巅&gt;&gt;阅读笔记二
  5. Building Java Projects with Gradle
  6. Java的JDK下Hashtable与HashMap的区别
  7. MES方向准备
  8. 关于python 自带csv库的使用心得 附带操作实例以及excel下乱码的解决
  9. 装CentOS 系统
  10. 使用 jstack 查询线程死锁错误日志 定位问题