Alex’s Game(I)
来源:互联网 发布:博奥软件官网 编辑:程序博客网 时间:2024/06/15 23:36
F - Alex’s Game(I)
Time Limit:1000MS Memory Limit:65535KB 64bit IO Format:%I64d & %I64uDescription
Alex likestoplay with one and zero!One day he gets an empty string.So our cute boy wants to add one and zero in it. Every time he will add ‘01’in the string at any position and then get a new string.For example:if the string is “01” now ,he can get “0101” or “0011,Now give you a string that is Alex has get,you need to answer whether the string is legal?
Input
First is a integer n(n<=100)
Next contains n lines .Every line is a string whose legth is no more than 1000.
Next contains n lines .Every line is a string whose legth is no more than 1000.
Output
For each case output "YES" in a single line if it’s legal.
Or you need to output “NO”;
Or you need to output “NO”;
Sample Input
3010101100011
Sample Output
YESNOYES题意:往一个空序列中插入字符串01,问输入的字符串是否满足要求思路:因为不管怎么插入0总是在1前面插入,所以只要按照顺序计算0和1的个数就行了。在计算时比较0和1的个数,如果1的个数大于0的个数,就不符合要求。#include<stdio.h>#include<string.h>int main(){ char ch[1005]; int n; scanf("%d",&n); while(n--) { scanf("%s",ch); int len=strlen(ch); int s0=0,s1=0; int flag=1; for(int i=0;i<len;i++) { if(ch[i]=='0') s0++; else s1++; if(s1>s0) { flag=0; break; } } if(flag==0) printf("NO\n"); else printf("YES\n"); } return 0;}
0 0
- Alex’s Game(I)
- Alex’s Game(I)
- NOJ——1627Alex’s Game(II)(尺取)
- NOJ——1628Alex’s Game(III)(DFS+回溯)
- caffe教程翻译:Alex’s CIFAR-10 tutorial, Caffe style
- i-s
- I Love This Game!
- I Love This Game
- I Love This Game
- [LeetCode] Jump Game I
- Jump Game I , II
- FZU:I. Fire Game
- jump game I // II
- Game Study I
- Jump Game I,II
- 1889. Max’s game
- 【poj2348】Euclid's Game
- 10905 - Children's Game
- android tv-TV Apps Checklist
- WordPress添加WP-PostViews插件显示访问量
- Day5_鬼代码/加密
- git SSH Key生成步骤
- C++学习笔记之三五法则
- Alex’s Game(I)
- Java 入门 之 面向对象 封装、继承与多态(二)
- C#程序开发中经常遇到的10条实用的代码
- Codeforces Round 331 (Div 2)BWilbur and Array(贪心)
- awesomeplayer_event 分析
- Java内存管理再探究
- Fragment与activity生命周期详细图解
- Day5_易语言/中文编程
- storyBoard