Better Passwords

#include <iostream>

using namespace std;

int main() {
	char A[40],B[40];
	cin>>A;
	if(A[0]>='a' && A[0]<='z') B[0]=A[0]-32;
	else B[0]=A[0];
	for(int i=1,j=1; i<40; i++,j++){
		if(A[i]=='s') B[j]='$';
		else if(A[i]=='i') B[j]='!';
		else if(A[i]=='o'){
			B[j]='(';
			j++;
			B[j]=')';
		}
		else if(A[i]=='\0'){
			B[j]='.';
			j++;
			B[j]='\0';
		}
		else B[j]=A[i];
	}
	cout<<B;
	return 0;
}

It shows runtime error, but I am unable to find the problem. Please help.

You need a condition in your loop to make it stop when you reach the end of the input string.

1 Like

Please Help

(Python 3.7)

A=input()
new=’’
if A[0]!=‘s’ and A[0]!=‘i’ and A[0]!=‘o’:
new=new+A[0].upper()
for i in range(len(A)):
if A[i]==‘s’:
new=new+’$’
elif A[i]==‘i’:
new=new+’!’
elif A[i]==‘o’:
new=new+’()’
else:
new=new+A[i]
new=new+’.’
print(new)

Please help me with this one.

(Python 3.7)

A=input()
if A[0]!=‘s’ and A[0]!=‘i’ and A[0]!=‘o’:
A=A.replace(A[0], A[0].upper())
A=A.replace(‘s’,’$’)
A=A.replace(‘i’,’!’)
A=A.replace(‘o’,’()’)
A=A+’.’
print(A)

It’s showing a wrong answer.

A=A.replace(A[0], A[0].upper())

I think you got wrong hoe the replace() function works.
Try different ways of capitalizing the 1st character.
It’s showing WA cause it is producing WA.
for inputs like aba, your code will capitalize every a word and will show AbA.

1 Like

Okay! That’s gonna be a pain.

What’s the output for “option” here? “Opt!()n.” or “()pt!()n.”?

#include <stdio.h>
int main()
{
    char str[100];
    int i,j,len;
    len=0;
    gets(str);
    if(str[0]>=97&&str[0]<=122)
    {
        printf("%c",str[0]-32);

    }
    else if(str[0]=='s')
    {
    printf("$");
    }
    else
    {
        printf("%c",str[0]);
    }
    

    for(i=0; str[i]!='\0'; i++)
    {

        len++;

    }
    for(j=1; j<=len; j++)
    {


        if(str[j]=='s')
        {
            printf("$");

        }
        else if(str[j]=='i')
        {
            printf("!");

        }
        else if(str[j]=='o')
        {
            printf("()");

        }

        else
        {
            printf("%c",str[j]);
        }


    }
    printf(".");
    return 0;


}

This code runs perfectly in my IDE and yields the correct shown output,but in Toph it shows a question mark at the end,please help

What is the problem with this code ?
I ran more than 20 words and it perfectly show me the expected answer on my IDE.
**** Python *****

word = []
a = input().lower()
if len(a) < 16:

for x in a:
    if x == 's':
        x = '$'
    if x == 'i':
        x = '!'
    if x == 'o':
        x = '()'
    word.append(x)
if word[0] == '$':
    word[0] = 's'
if word[0] == '!':
    word[0] = 'i'
if word[0] == '()':
    word[0] = 'o'

for y in word:
    if y == word[0]:
        print(word[0].upper(), end='')
    else:
        print(y, end='')

print(’.’)

/******************************************************************************

                          Online C++ Compiler.
           Code, Compile, Run and Debug C++ program online.

Write your code in this editor and press “Run” button to compile and execute it.

*******************************************************************************/

#include

using namespace std;

int main()
{

string password;
cin>>password;
//password[0]=password[0]-32;

char betterpassword[16];

int i=0,j=0;
for(j=0;j<password.length();j++){
if(password[j]=='s'){
betterpassword[i]='$';
i++;
}    
else if(password[j]=='i'){
betterpassword[i]='!';
i++;
}    
else if(password[j]=='o'){
betterpassword[i]='(';
i++;
betterpassword[i]=')';
i++;
}    
else {
betterpassword[i]=password[j];
i++;
}

}
if(password.length()==j){
betterpassword[i]=’.’;
}
//unsophisticated
cout<<betterpassword;

return 0;

}
why

s = str(input())
if len(s) < 16:
    u = s.replace(s[:1], s[:1].upper())
    u = u.replace('s', '$')
    u = u.replace('i', '!')
    u = u.replace('o', '()')
    print(u + '.')

This gets the ‘wrong answer’ in the 5th test case. I don’t know what’s wrong
with it.

Inspired by JavaScript’s random problem,
This is how the code is written in python 3.8
Even a newbie can write something like this…

This problem is created for newbies in the first place. So, I would appreciate it if you do not post solves in the community. Just give clues.

u = s.replace(s[:1], s[:1].upper())

@Aurjon the replace function doesn’t work this way. It takes a string and replaces it with another string. This, just change the first character separately.

Uncomment this line maybe?