codeforces 96A (字符串模拟水题)
来源:互联网 发布:德国警察 知乎 编辑:程序博客网 时间:2024/06/05 03:20
点击打开题目
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed100 characters. There's at least one player from each team present on the field.
Print "YES" if the situation is dangerous. Otherwise, print "NO".
001001
NO
1000000001
YES字符串的简单处理,求是否有连续七个的0或者连续七个的1;╮(╯▽╰)╭此题也wa几次,细节又忽略掉了,↖(^ω^)↗代码:#include <iostream>#include<string.h>using namespace std;int main(){ char s[101]; bool flag; int i,j,k,ans; while(cin>>s) { flag=true; k=strlen(s); for(i=0; i<k; i++) { if(s[i]=='0') { //cout<<i<<endl; ans=0; for(j=i; j<k; j++) { ans++; if(s[j]=='1') { i=j-1; ans--; break; } else if(ans==7) { break; } } if(ans==7) { cout<<"YES"<<endl; flag=false; break; } } else if(s[i]=='1') { ans=0; for(j=i; j<k; j++) { ans++; if(s[j]=='0') { i=j-1; ans--; break; } else if(ans==7) { break; } } if(ans==7) { cout<<"YES"<<endl; flag=false; break; } } } if(flag) cout<<"NO"<<endl; } return 0;}
- codeforces 96A (字符串模拟水题)
- Codeforces 2A. Winner(字符串:模拟)
- codeforces 600 A. Extract Numbers(字符串模拟)
- codeforces 141A Amusing Joke(模拟水题)
- codeforces 116A Tram(模拟水题)
- Codeforces 631A Interview【模拟水题】
- Codeforces 390A( 模拟题)
- CodeForces - 404A(模拟题)
- codeforces 133A HQ9+(字符串水题)
- codeforces 435A Queue on Bus Stop(模拟水题)
- codeforces 131A cAPS lOCK(模拟水题)
- codeforces 119A Epic Game(模拟水题)
- CodeForces--606A --Magic Spheres(模拟水题)
- CodeForces - 651A Joysticks (找规律&模拟)水
- CodeForces - 584A Olesya and Rodion (模拟)水
- CodeForces - 658A Bear and Reverse Radewoosh (模拟)水
- CodeForces - 557A Ilya and Diplomas (模拟)水
- CodeForces - 236A Boy or Girl (模拟)水
- 几张图看懂Oracle 你想要的 这里都有
- checkbox多选删除
- RT-Thread操作系统之—IPC
- HDU1372 跳马问题(bfs)
- POJ 2388 Who's in the Middle
- codeforces 96A (字符串模拟水题)
- 三层架构实战篇 上
- 高斯白噪声(White Gaussion Noise)的内容与实现
- oracle RAC集群体系结构
- sql数据类型
- 基于Linux C的聊天室客户端(一)传输规范
- 什么情况
- java学习记录(三):引用类型的概念
- android4.4电源管理——Input系统(Power键处理)