【水I/O】#20 A. BerOS file system
来源:互联网 发布:js ip地址正则表达式 编辑:程序博客网 时间:2024/06/05 06:41
——————————————————————————
《Updated 2015/07/15》
回头来看了看这题,觉得以前写的还是略显凌乱,写了一个用STL-String的
AC-Code:
#include <cstdio> #include <string>#include <cstring> #include <iostream> //http://blog.csdn.net/okcd00/article/details/27373475using namespace std; int main() {string s,ans=""; cin>>s; int len=s.length();while(s[len-1]=='/')len--;s=s.substr(0,len);for(int i=0;i<len;i++){if(s[i]!='/') ans=ans+s[i];else if(i+1<len && s[i+1]!='/') ans=ans+s[i];}if(ans.length()==0)cout<<'/'<<endl;else cout<<ans<<endl;return 0; }
——————————————————————————
看到这道题,吾辈欣喜了一小会~,哇咔咔,水题,秒~
然后写了这个:
#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>using namespace std;int main(){bool flag=true;char tmp;while(scanf("%c",&tmp)!=EOF){if(tmp=='/')flag=true;else if(tmp!='/'&&flag==true){printf("/%c",tmp);flag=false;}else if(tmp!='/'&&flag==false)printf("%c",tmp);}return 0;}
然后……WA了…… 原因是///a//这样的case输出了/a/ 多了一个结尾的/,百思不得其解
然后,
wrong output format Unexpected end of file - token expected
再然后:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int main() {char str[1000]; while(scanf("%s", str) != EOF) //get the whole line{ int len = strlen(str);//length for( int i=0; i<len; i++ ) { if(str[i] == '/') //把连在一起的'/'换成'.'只留一个'/' { i++; while(i<len && str[i] == '/') //下一个(不超出字符串)是否为'/' { str[i] = '.'; i++; } i--; } } int k = 0; char ans[1000]; for( int i=0; i<len; i++ ) if(str[i] != '.') ans[k++] = str[i]; while(k>0 && ans[k-1] == '/') k--; ans[k] = '\0';//end if(k == 0) printf("/\n"); else printf("%s\n", ans); } return 0;}
0 0
- 【水I/O】#20 A. BerOS file system
- A. BerOS file system
- cf 20a BerOS file system
- Code Forces 20A BerOS file system
- CodeForces 20A BerOS file system (简单题)
- CDOJ_327 BerOS file system
- Overcoming the I/O Bottleneck with General Parallel File System
- Bypassing Raw File System I/O Rootkit Detector
- Low-level I/O 和 File System Interface
- Low-level I/O 和 File System Interface
- Linux System Programming note 2 ——File I/O
- Java File I/O :Reader/Writer and when a Stream
- IOBYFILE.C---overlapped I/O with a signaled file handle
- linux file I/O
- Linux file I/O
- C++ File I/O
- FILE I/O
- Multithreaded File I/O
- Excel中的单元格引用
- POJ - 1111 Image Perimeters
- java计算时间差
- android camera(三):camera V4L2 FIMC
- 什么是stub?
- 【水I/O】#20 A. BerOS file system
- hibernate 原理(ORM)及接口
- eclipse调试hbase,mapreduce
- 如何添加、彻底删除Tomcat服务 将解压版的Tomcat设为windows服务
- 值得IT人员浏览的站点
- 深入推荐引擎相关算法 - 协同过滤
- 迷惑:数据库和VFP的区别
- 设计模式总结之没有结束的结尾
- boss来学校演讲,希望不久的将来演讲的是我!