Relative Content

Tag Archive for c++string

Check if string has any consecutive repeating substring in it

I want to accept only strings that do not have any substring repeated three times consecutively in them. The substring is not known in advance. For example, “a4a4a4123” contains “a4”; “abcdwwwabcd” – “w”; “abcde” – valid, no triple repeats.

Check if string has any consecutive repeating substring in it

I want to accept only strings that do not have any substring repeated three times consecutively in them. The substring is not known in advance. For example, “a4a4a4123” contains “a4”; “abcdwwwabcd” – “w”; “abcde” – valid, no triple repeats.

Text after the space is not being printed

I take in a string (e.g. 3 6) the string will always be two one digit numbers separated by one space. I have access to the first number, but for some reason I loose access to the second one.

Command exited with non-zero status 124

#include <bits/stdc++.h> using namespace std; int main() { size_t t,n,m,k;cin>>t; string a; while(t–){ cin>>n>>m>>k>>a; if(m>n){ cout<<“YESn”; continue;} for(size_t i=0;i<n;){ if(i=a.find(“L”,i))!=string::npos){ if(m+k>=a.find(“L”,i)){ if(n-i<=m+k) {cout<<“YESn”; break;} } else{ cout<<“NOn”; break;} }} } return 0; } so basically i have to cross a river of length n , with C (crocodiles) ,L(logs) in it but upon running it […]

terminate called after throwing an instance of ‘std::out_of_range’ what(): basic_string::erase: __pos (which is 18446744073709551615)

#include <bits/stdc++.h> using namespace std; int main() { string a,b; cin >> a; b=”WUB”; int n; while(a.find(b)==0){ a.erase(0,3); } while(a.find(b)>0){ n=a.find(b); a.replace(n,3,” “); } n=a.size(); while(a[–n]==’ ‘){ a.erase(n,1); } cout<<a; return 0; } basically i have to remove WUB from the input string and if its between words then switch it with space but i […]

char s[] and char *s not the same?

I always though that char s[] and char *s were essentially the same in simple C functions.
Yet the following code gives me a segmentation fault at runtime.

Comparing a string that is reversed is not working

I am using the below function and getting the below output. Can someone please explain why.
It prints out that they are equal after the for loop finishes but when compared the logic says they are not equal.

How to add a two-digit number to stack

I am currently writing a code that inputs a function as a string from the user, coverts it to a postfix expression, then converts it to infix, then evaluates the expression.