Skip to content

Instantly share code, notes, and snippets.

@BayronVazquez
Last active August 12, 2022 01:56
Show Gist options
  • Save BayronVazquez/4ca5b1d383855a64bcbcdaea66e567d6 to your computer and use it in GitHub Desktop.
Save BayronVazquez/4ca5b1d383855a64bcbcdaea66e567d6 to your computer and use it in GitHub Desktop.
You need to revive the good old Spongebobmeme!. YoU kNoW wAhT i MeAn! The first letter should be capitalized, the second lower, the third again capitalized,... and so on.

Goal

You need to revive the good old Spongebobmeme!.

YoU kNoW wAhT i MeAn!

The first letter should be capitalized, the second lower, the third again capitalized,... and so on.

Input

The string: input which need to be converted.

Output

A string with the correct converted input.

Constraints

input is at least 2 characters long.

<?php
$input = stream_get_line(STDIN, 256 + 1, "\n");
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
// To debug: error_log(var_export($var, true)); (equivalent to var_dump)
$mayuscula = true;
for($i =0; $i < strlen($input); $i++)
{
if (ctype_alpha($input[$i]))
{
if($mayuscula)
{
echo strtoupper($input[$i]);
$mayuscula = false;
}
else
{
echo strtolower($input[$i]);
$mayuscula = true;
}
}
else
{
echo $input[$i];
}
}
?>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
int main()
{
string s;
getline(cin, s);
int j = 0;
for (int i = 0; i< s.length(); i++) {
if (!isalpha(s[i])) {
cout << s[i];
continue ;
}
if (!(j++&1))
s[i] = toupper(s[i]);
else
s[i] = tolower(s[i]);
cout << s[i];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment