-
-
Save lazycipher/be9df4b24a059afa8ed8e9dc9b2b28c3 to your computer and use it in GitHub Desktop.
| #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; | |
| } |
#Simple LOGIC
q = "0000000"
p = "1111111"
k = input()
if q in k or p in k:
print("YES")
else:
print("NO")
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;
}
i dont need any header though its python-magic ..
no magics for python mate
i <= s1.length()
Isn't that a potential error? As s[i] would be invalid if that ever happens? Did you test this code?
#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;
}
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;
}
life is easy,,
if(s.find("0000000")!=-1||s.find("1111111")!=-1)
cout<<"YES";
else
cout<<"NO";
#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."
#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 ??