Skip to content

Instantly share code, notes, and snippets.

@lazycipher
Created June 7, 2019 06:12
Show Gist options
  • Select an option

  • Save lazycipher/be9df4b24a059afa8ed8e9dc9b2b28c3 to your computer and use it in GitHub Desktop.

Select an option

Save lazycipher/be9df4b24a059afa8ed8e9dc9b2b28c3 to your computer and use it in GitHub Desktop.
Codeforces 96A Football Solution C++
#include<iostream>
using namespace std;
int main(){
string s1;
cin>>s1;
int condition = 1;
for(int i=1; i<=s1.length(); i++){
if(s1[i] == s1[i-1]){
condition++;
if(condition==7){
cout<<"YES"<<endl;
return 0;
}
}else{
condition=1;
}
}
cout<<"NO"<<endl;
return 0;
}
@dakshg51

Copy link
Copy Markdown

#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
if(s.find("0000000")<100||s.find("1111111")<100){
cout<<"YES";
return 0;
}
cout<<"NO";
return 0;
}
//is this a good code ??

@KishanMishra1

Copy link
Copy Markdown

#Simple LOGIC
q = "0000000"
p = "1111111"
k = input()
if q in k or p in k:
print("YES")
else:
print("NO")

@L0rd-AK

L0rd-AK commented Jan 3, 2022

Copy link
Copy Markdown

your code is wrong
you didn't even declare header file

#include
#include
using namespace std;

int main()
{
int count=0;
string s;
cin>>s;
for(int i=0;i<s.length();i++)
{
if(s[i]==s[i+1])
{
count++;
if(count==6)
{
cout<<"YES"<<endl;
return 0;
}
}
else
{
count=0;
}
}
cout<<"NO"<<endl;
return 0;
}

@KishanMishra1

Copy link
Copy Markdown

i dont need any header though its python-magic ..

@ImErdis

ImErdis commented Feb 17, 2022

Copy link
Copy Markdown

no magics for python mate

@a-n-irwin

Copy link
Copy Markdown

i <= s1.length()

Isn't that a potential error? As s[i] would be invalid if that ever happens? Did you test this code?

@zihadul10101

zihadul10101 commented Nov 10, 2023

Copy link
Copy Markdown

#include <bits/stdc++.h>
using namespace std;

int main()
{
string s;
cin>>s;
int ans=0;

for(int i=0;i<s.size();i++){
    int count=0;
    if(s[i]=='0'){
       while(s[i]=='0' && i<s.size()){
           count++;
           i++;
       }
    }else{
       if(s[i]=='1'){
       while(s[i]=='1' && i<s.size()){
           count++;
           i++;
       }  
    }
    i--; 
    }
   if(count>=7){
        ans=1;
    }
}

if(ans==1){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
return 0;
}

@suniyao

suniyao commented Mar 4, 2024

Copy link
Copy Markdown

Hi guys this is my code and seems to have a different logic compared to yours. However, when testing, I don't understand why my code is wrong at test 42. Can you help me figure out which part of the code is wrong, thanks so much!

// https://codeforces.com/problemset/problem/96/A
#include <iostream>
#include <string>
using namespace std;

int main(){
    string str;
    cin >> str;
    int l = str.length();
    int sum[l+1];
    sum[0] = 0;
    for (int i = 1; i <= l; i++){
        sum[i] = sum[i-1] + (str[i-1] - '0');
    }
    bool found = false;
    for (int i = 1; i <= l-7; i++){
        if (sum[i+7]-sum[i] == 7 || sum[i+7]-sum[i] == 0){
            found = true;
            break;
        }
    }
    if (found){
        cout << "YES";
    }
    else{
        cout << "NO";
    }
    return 0;
}

@SFbijoy

SFbijoy commented Oct 14, 2024

Copy link
Copy Markdown

life is easy,,
if(s.find("0000000")!=-1||s.find("1111111")!=-1)
cout<<"YES";
else
cout<<"NO";

@Arani2021

Copy link
Copy Markdown

#include
using namespace std;
int main()
{
string s;
cin>>s;
int ans=0;
for(int i=0;i<s.size();i++)
{
int cnt=0;
if(s[i]=='0')
{
while(s[i]=='0' && i<s.size())
{
cnt++;
i++;
}
}
else{
while(s[i]=='1' && i<s.size())
{
cnt++;
i++;
}
}
if(cnt>=7) ans=1;
i--;
}
if(ans==1)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}

// Approach
1.Input Handling: The program takes a binary string s as input and initializes ans to 0. This ans variable will act as a flag to indicate if a sequence of 7 or more consecutive '0's or '1's is found.

2.Iterating Over the String: Using a for loop, it iterates through each character of the string. Inside this loop, a variable cnt is initialized to 0 for each new character. cnt keeps track of the count of consecutive '0's or '1's.

3.Counting Consecutive Characters:

    i.If s[i] is '0', it enters a while loop to count all consecutive '0's until a different character or the end of the string is encountered.
    ii.Similarly, if s[i] is '1', it enters another while loop to count consecutive '1's.

4.Checking Length of Sequence: After exiting the while loop, it checks if cnt (the count of consecutive '0's or '1's) is 7 or more. If so, it sets ans to 1, indicating that such a sequence exists. The loop then continues to scan the rest of the string.

5.Final Output: After the loop completes, it checks the value of ans. If ans is 1, it prints "YES," indicating a sequence of 7 or more consecutive '0's or '1's was found; otherwise, it prints "NO."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment