Question-
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 least 7 players of some team standing one after another, then the situation is considered dangerous.
For example, the situation 00100110111111101 is dangerous and 11110111011101 is not.
You are given the current situation. Determine whether it is dangerous or not.
Explanation-
1)We have to find continuous seven zeroes or ones i.e., ("0000000") or ("1111111").
2)First make an array of char type size equal to 100 sunce required length of string is 100.
3)Take its input and define a pointer which will be having the value returned by strstr function
(you can read more about strstr function on geeksforgeeks or simply search on google and read on any of the sites)
4)It find you the first occurrence of ("0000000") or ("1111111") and required output will be printed.
Program-
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 least 7 players of some team standing one after another, then the situation is considered dangerous.
For example, the situation 00100110111111101 is dangerous and 11110111011101 is not.
You are given the current situation. Determine whether it is dangerous or not.
Explanation-
1)We have to find continuous seven zeroes or ones i.e., ("0000000") or ("1111111").
2)First make an array of char type size equal to 100 sunce required length of string is 100.
3)Take its input and define a pointer which will be having the value returned by strstr function
(you can read more about strstr function on geeksforgeeks or simply search on google and read on any of the sites)
4)It find you the first occurrence of ("0000000") or ("1111111") and required output will be printed.
Program-
#include<iostream>
#include<cstring> // C type string used as a standard namespace in C++
using namespace std; int main() { char s[100]; cin>>s; char *p; if(p=strstr(s,"1111111")) // p returns a value other than zero cout<<"YES"; else if(p=strstr(s,"0000000")) cout<<"YES"; else cout<<"NO"; }Link to the question on Codeforces-https://codeforces.com/problemset/problem/96/A
Nyc sir
ReplyDeleteThank you....keep supporting
DeleteVery helpful...keep it up sir
ReplyDeleteThankx
ReplyDelete🙏🏻🙏🏻
ReplyDeleteIt's quite helpful,upload some more problems with solutions.
ReplyDeleteSure
Delete