+ 7

Question about Solution: Pig Latin

I carefully read the task - and even solved it in two ways (in C and Python), however, both of my solutions fail test # 3 without explaining the reason .... that is, I myself have to guess what’s there in some kind of test, which you came up with, could go wrong, and therefore fix something that would go wrong;) ... Your test should write an example of input, what went wrong ....... You (Dear the creators of this Task) can help me in this situation? Thanks.

19th Dec 2019, 9:11 PM
Michail Getmanskiy
Michail Getmanskiy - avatar
13 odpowiedzi
+ 4
It seems like the third case has a word with a character not in the range [a, z] and different from a blank space, so your code splits that word in two when it shouldn't. For example: Input: hello#world Output: ellohay#orldway Expected (?): ello#worldhay Change your first condition to if (c != ' '): # Not a blank space and everything should work correctly.
19th Dec 2019, 9:50 PM
Diego
Diego - avatar
+ 5
We, the community, can also help you. You can post your solution and someone will surely look into it.
19th Dec 2019, 9:16 PM
Diego
Diego - avatar
+ 4
In C, the code is similar, only the output is not used immediately, but the char * array is being formed, and then it is printed.
19th Dec 2019, 9:22 PM
Michail Getmanskiy
Michail Getmanskiy - avatar
7th Jan 2020, 1:09 AM
Paul K Sadler
Paul K Sadler - avatar
+ 3
Diego: yes - that’s how it goes, damn it, but something else is written in the assignment: Input Format A string of the sentence in English that you need to translate into Pig Latin. (no punctuation or capitalization)
19th Dec 2019, 10:04 PM
Michail Getmanskiy
Michail Getmanskiy - avatar
+ 3
Farhan: Thanks. I already solved this problem, but your option is different ... Thank you.
21st Dec 2019, 5:51 PM
Michail Getmanskiy
Michail Getmanskiy - avatar
+ 2
perhaps in the description of the problem, speaking of words, is it meant with the exception of prepositions?
19th Dec 2019, 9:42 PM
Michail Getmanskiy
Michail Getmanskiy - avatar
+ 2
My code is shorter. Maybe this can also help you: def solve(s): y=[] s=s.split(" ") for i in s: i=i+i[0]+"ay" y.append("".join(i[1:])) return " ".join(y) print(solve(input()))
21st Dec 2019, 5:48 PM
Ishmam
Ishmam - avatar
+ 1
text = input() w=False fcw = '0' for c in text: if (c>='a' and c<='z'): if w == False: w = True fcw = c else: print(c,end="") else: if w == True: w = False print(fcw+"ay",end="") print(c,end="") if w == True: w = False print(fcw+"ay",end="")
19th Dec 2019, 9:19 PM
Michail Getmanskiy
Michail Getmanskiy - avatar
+ 1
Michail Getmanskiy Oh, thanks. There are many ways to solve a single problem.
21st Dec 2019, 5:54 PM
Ishmam
Ishmam - avatar
+ 1
Michail Getmanskiy your code seemed a bit complex to me. That's why I posted a different way to solve that problem.
21st Dec 2019, 5:56 PM
Ishmam
Ishmam - avatar
+ 1
//Using c++ check this out.. It works.. //#Daniel theProgrammer #include <iostream> using namespace std; int main() { string s, a, pig; getline(cin, s); for(int i = 0; s[i] != '\0'; i++){ a += s[i]; if(s[i+1] == ' ' || s[i+1] == '\0'){ a = a.substr(1) + a[0] + "ay"; pig += a + ' '; i++; a = ""; } } cout << pig; return 0; }
10th May 2020, 10:13 AM
Nji Daniel
Nji Daniel - avatar
11th May 2020, 9:29 PM
Wilfried-Tech
Wilfried-Tech - avatar