Zeros and Ones
2013-11-23 23:28
225 查看
题目描述
Consider strings of characters made up by concatenating any number of the strings 0, 01 or 11.
For example 00011111 is one such string, as is 001011, but 1011 is not. Your job is simply to determine if a given string can be constructed in this manner.
输入
There will be multiple problem sets. Input for each problem will be on one line. Each line (except
the last) will be of the form
n s
where n is a non-negative integer no larger than 100 and s is a string of 0’s and 1’s of length n.
A value of n = 0 indicates end of input.
输出
Each problem should generate one line of code, either,
String m can be generated.
or
String m can not be generated.
accordingly, where m is the number of the problem (stating at 1).
样例输入
8 00011111
6 001011
4 1011
0
样例输出
String 1 can be generated.
String 2 can be generated.
String 3 can not be generated.
题目意思是输入一个由0,1组成的字符串检测其是否能由0,01,11这几个字符串构成。规律就是只有是奇数个1开头的字符串不符合题意。源代码如下:
#include<iostream> using namespace std; int main() { int n,j=1,i; char s[102]; while(cin>>n&&n) { for(i=0;i<n;i++) cin>>s[i]; for(i=0;s[i]=='1'&&i<n;i++); if(i%2) cout<<"String "<<j<<" can not be generated."<<endl; else cout<<"String "<<j<<" can be generated."<<endl; j++; } return 0; }
相关文章推荐
- py2exe 打包 pyqt程序的图片不显示的问题
- ACM 进阶学习第一课----同余相关之中国剩余定理
- ThingPHP学习笔记
- wordpress迁移
- 【总结】2013年,再见ACM/ICPC
- ListView ClassCastException:
- ios文件操作
- CFindFile的用法
- 关键路径——杭电 4109
- Python--如何组织项目
- ThingPHP学习笔记
- 面向对象一点思考
- 笔记本网络连接状况未知,依赖服务或组无法启动
- 【转】C++及java在内存分配上的区别
- 关于行和列的算法
- Web安全之CSRF
- (work and tools)linux压缩格式简析
- 总结几种C#窗体间通讯的处理方法
- Deep Learning学习网站
- 修改Ubuntu和WIN7双系统的默认启动系统