system
December 22, 2019, 6:40pm
1
Shamim bought a second-hand printer. However, there was a fault in that printer. The printer is prin…
Click here to read the complete problem statement.
If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.
#include <bits/stdc++.h>
using namespace std;
int main()
{
char k[]="the end.";
char s[105];
int i=0;
while(gets(s))
{
if(strcmp(k,s)==0)
break;
i=0;
while(s[i]!='.')
{
if(s[i]=='b')
s[i]=54;
if(s[i]=='g')
s[i]=57;
if(s[i]=='l')
s[i]=49;
if(s[i]=='o')
s[i]=48;
if(s[i]=='s')
s[i]=53;
if(s[i]=='z')
s[i]=50;
i++;
}
puts(s);
}
}
what is the problem in this code?
mdvirus
December 28, 2019, 9:32am
3
The trick for this problem is this line
The printer is printing certain English numbers instead of certain English letters. But if we write those numbers and print it, then the printer prints the letters instead of printing those numbers.
So think, what if Shamim wants the numbers to print with the printer?
1 Like
mdvirus
December 30, 2019, 1:03pm
5
@MahmudX
You’ve got the trick. Just remove the comment characters (// ) from your code and then submit. It will pass all the cases then.
1 Like
MahmudX
December 30, 2019, 5:13pm
6
At my first attempt, they weren’t commented out, I still got the same result. That’s why I wanted to know what’s wrong!
mdvirus
December 30, 2019, 5:53pm
7
@MahmudX
After else block in line 11, you’re replacing 4
with l
. It should be 1
with l
. That is the problem.
1 Like
MahmudX
December 30, 2019, 5:58pm
8
https://toph.co/s/416189
Hi I fixed this, but still got the error.
@mdvirus
mdvirus
December 31, 2019, 10:47am
9
@MahmudX
I don’t know the C# language. But I checked your code with custom input and saw, for this case your program doesn’t shows the right output:
691052
the end.
It’s your duty to find the bug.
1 Like
@hjr265
What is the problem in my code?
#include <stdio.h>
#include <string.h>
int main()
{
while(1)
{
char c[101];
char d[] = "the end.";
scanf(" %[^\n]", c);
if(strcasecmp(c, d) == 0)
{
return 0;
}
for(int i = 0; i < strlen(c); i++)
{
if(c[i] == 'b')
{
c[i] = '6';
}
else if(c[i] == 'g')
{
c[i] = '9';
}
else if(c[i] == 'l')
{
c[i] = '1';
}
else if(c[i] == 'o')
{
c[i] = '0';
}
else if(c[i] == 's')
{
c[i] = '5';
}
else if(c[i] == 'z')
{
c[i] = '2';
}
else if(c[i] == '6')
{
c[i] = 'b';
}
else if(c[i] == '9')
{
c[i] = 'g';
}
else if(c[i] == '1')
{
c[i] = 'l';
}
else if(c[i] == '0')
{
c[i] = 'o';
}
else if(c[i] == '5')
{
c[i] = 's';
}
else if(c[i] == '2')
{
c[i] = 'z';
}
}
puts(c);
}
}
how can i handle the 1 and l. I think there is the problem why this code is not accepted
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
ll a,i;
string s;
while(getline(cin,s))
{
if(s=="the end.")
break;
for(i=0;i<s.size();i++)
{
if(s[i]=='b')
s[i]='6';
else if(s[i]=='g')
s[i]='9';
else if(s[i]=='l')
s[i]==49;
else if(s[i]=='o')
s[i]='0';
else if(s[i]=='s')
s[i]='5';
else if(s[i]=='z')
s[i]='2';
else if(s[i]=='6')
s[i]='b';
else if(s[i]=='9')
s[i]='g';
else if(s[i]=='1')
s[i]=='l';
else if(s[i]=='0')
s[i]='o';
else if(s[i]=='5')
s[i]='s';
else if(s[i]=='2')
s[i]='z';
}
cout<<s<<endl;
}
return 0;
}
what is a problem my code please answer
arr=[]
i=0
j=0
while True:
li = input()
arr.append(li)
value=list(li)
for j in range(len(value)):
if value[j]=="b":
value[j]="6"
elif value[j]=="g":
value[j]="9"
elif value[j]=="l":
value[j]="l"
elif value[j]=="o":
value[j]="0"
elif value[j]=="s":
value[j]="5"
elif value[j]=="z":
value[j]="2"
s = value
listToStr = ''.join(map(str, s))
if listToStr=="the end.":
break
print(listToStr)
i+=1
SyedZia
November 4, 2020, 8:42pm
15
Can any body yell me what’s wrong with my code:
#include <stdio.h>
#include <string.h>
int main()
{
char A[100000],end[] = “the end.”;
int i;
gets(A);
if(0 == strcmp(A,end)){
return 0;
}else{
for(i = 0;i < strlen(A);i++){
if(A[i] == 'o'){
printf("0");
}
else if(A[i] == 'b'){
printf("6");
}
else if(A[i] == 'l'){
printf("1");
}
else if(A[i] == 'g'){
printf("9");
}
else if(A[i] == 's'){
printf("5");
}
else if(A[i] == 'z'){
printf("2");
}
else{
printf("%c",A[i]);
}
}
}
return 0;
}