0% found this document useful (0 votes)
58 views

Coderbyte

The document contains code snippets from 4 different programs that perform string validation and manipulation tasks: 1) The first program defines a StringChallenge function that reverses a user-input string and returns it. 2) The second program defines a SearchingChallenge function that validates if a string is between 4-25 characters long, starts with a letter, and ends with an underscore, returning the string or "0". 3) The third program finds the longest palindrome substring in a user-input string, returning the substring or "not possible". 4) The fourth program contains unlabeled code that may perform additional string validation or manipulation tasks.

Uploaded by

Delaafifah
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Coderbyte

The document contains code snippets from 4 different programs that perform string validation and manipulation tasks: 1) The first program defines a StringChallenge function that reverses a user-input string and returns it. 2) The second program defines a SearchingChallenge function that validates if a string is between 4-25 characters long, starts with a letter, and ends with an underscore, returning the string or "0". 3) The third program finds the longest palindrome substring in a user-input string, returning the substring or "not possible". 4) The fourth program contains unlabeled code that may perform additional string validation or manipulation tasks.

Uploaded by

Delaafifah
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

nomer 2

#include <iostream>
#include <string>
using namespace std;

string StringChallenge(string str) {

cout<<"Enter some text: ";


cin>>str;
string reverseString;

for(long i = str.size() - 1;i >= 0; --i){


reverseString += str[i];
} return str;

int main(void) {

// keep this function call here


cout << StringChallenge(coderbyteInternalStdinFunction(stdin));
return 0;

nomer 3
#include <iostream>
#include <string>
using namespace std;

string SearchingChallenge(string str) {

if((str.length()>=4 && str.length()<=25) &&(str[0]>='a' && str[0]<='z' ||


str[0]>='A' && str[0]<='Z') &&(str[str.length()-1]/='_'))
{
return str;
}
else
{
return "0";
}

int main(void) {

// keep this function call here


cout << SearchingChallenge(coderbyteInternalStdinFunction(stdin));
return 0;

Nomer 4
function StringChallenge(str) {

if(str === str.split("").reverse().join("")) {return str;};


let result = "";
for (let i = 0; i < str.length; i++) {
let items = str[i];
for (let j = i + 1; j < str.length; j++) {
items += str[j];
if (items === items.split("").reverse().join("")) {
if ( result.length < items.length) {result = items;}
}
}
}
return result.length < 3 ? "not possible" : result ;
}

// keep this function call here


console.log(StringChallenge(readline()));

Nomer 5

You might also like