This is a companion discussion topic for the original entry at https://toph.co/p/better-passwords
This is a companion discussion topic for the original entry at https://toph.co/p/better-passwords
#include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
char ara[20];
gets(ara);
if(ara[0] > 'a' && ara[0] < 'z') {
ara[0] = ara[0] + 'A' - 'a';
}
int l = strlen(ara), i, j;
ara[l] = '.';
l++;
for(i = 0; i < l; i++) {
if(ara[i] == 'i') {
ara[i] = '!';
}
else if(ara[i] == 's') {
ara[i] = '$';
}
else if(ara[i] == 'o') {
l++;
for(j = l; j > i + 1; j--) {
ara[j] = ara[j - 1];
}
ara[i] = '(';
ara[i + 1] = ')';
}
else {
continue;
}
}
for(i = 0; i < l; i++) {
printf("%c", ara[i]);
}
return 0;
}
it shows error after the fourth case , but it seems alright
use:-
if(ara[0] >= βaβ && ara[0] <= βzβ)
instead of:-
if(ara[0] > βaβ && ara[0] < βzβ)
@corrupted_brain try to solve it using python by yourself first. If you fail then you can ask us. Just donβt seek help before trying. You canβt improve that way. Easy problems are basic problems for beginners to try and learn. If you fail, then you can always free to ask here.
However, to take strings as input s = input()
should do. for example:
>>> input()
it is a string
'it is a string'
>>> s = input()
sample string
>>> s
'sample string'
>>> s[0]
's'
>>> s[1]
'a'
>>> len(s)
13
>>> for i in s:
... ... print(i)
...
s
a
m
p
l
e
s
t
r
i
n
g
This example should help you to learn about strings.
Let me add some more examples as a reference,
>>> s = "sample string"
>>> s
'sample string'
>>> l = list(s)
>>> l
['s', 'a', 'm', 'p', 'l', 'e', ' ', 's', 't', 'r', 'i', 'n', 'g']
>>> s[1]
'a'
>>> s[1] < 'b'
True
>>> s.count('s')
2
@corrupted_brain at least read the problem statement carefully.
You were told to make the first letter uppercase. For example, βaβ will be βAβ, βbβ will be βBβ , βcβ will be βCβ and so onβ¦
But your output was:
Fix this and your answer should be accepted. You can use the built-in function upper()
to do this.
read this https://www.geeksforgeeks.org/isupper-islower-lower-upper-python-applications/
in case if you take string input as βpoloβ you code will work for the first βoβ not for the second one βoββ¦check it out and think again β¦
This is an implementation problem. The expected solution is the obvious one (like the one you did).
I actually checked the output for your most recent submission. It seems you are printing an extra unreadable character at the end. So something is not right in the code I would assume.
Also, you donβt need to keep track of that flag and print conditionally. You can assume that the input will always be within the constraints.
when the first one is o or i or s , should I make it capital or change it to $,!,()
You should make it capital.
@Burn_Fireblaze, you should not share your solve if your code have already got accepted.
Please remove this type of posts that you have made, from everywhere.
okay. Removing it. r
Something is not right in the loop, when the char is βoβ.
Please help me to find it out.
#include <stdio.h>
#include<string.h>
int main()
{
char s[40], i, j;
int len;
gets(s);
len= strlen(s);
for(i=0; i<=len; i++)
{
if(s[i] == 's')
{
s[i]= '$';
}
else if(s[i] == 'i')
{
s[i]= '!';
}
else if(s[i] == 'o')
{
s[i]= '(';
for(j=len; j>i; j--)
{
s[j]=s[j-1];
len= strlen(s);
//printf("%d\n", len);
}
s[i+1]=')';
}
else
{
continue;
}
len= strlen(s);
}
if (s[0]>='a' && s[0]<='z')
{
s[0]= s[0]- 32;
}
int new_len=strlen(s);
s[new_len +1]='\0';
s[new_len]='.';
puts(s);
return 0;
}
You cannot use the gets
function here on Toph. and in line 19.
s[i] = '(';
^
you are replacing o
with (
but you were told to replace it with ()
. You forgot to capitalize the first letter also.
I will say, read the problem statement carefully.
This is capitalizing the First character. Moreover, read my codes once again. Please check the code by the sample input
Having the main problem with those garbage.
Why not try solving this problem using two character arrays? One for the input and the other where you build the password.
That way, you are less likely to make mistakes in the code.
For each character in the input array, you will put the necessary characters at the end of the output character array. You can track the βendβ of this array using an integer index. At the very, just put a β\0β (null character) to make it a string.
Thank you for your suggestion. Working on it.