0

How can I improve this possible solution

The problem Pig Latin You have two friends who are speaking Pig Latin to each other! Pig Latin is the same words in the same order except that you take the first letter of each word and put it on the end, then you add 'ay' to the end of that. ("road" = "oadray") Task Your task is to take a sentence in English and turn it into the same sentence in Pig Latin! Input Format A string of the sentence in English that you need to translate into Pig Latin. (no punctuation or capitalization) Output Format A string of the same sentence in Pig Latin. Sample Input "nevermind youve got them" Sample Output "evermindnay ouveyay otgay hemtay" Explanation The output should be the original sentence with each word changed so that they first letter is at the end and then -ay is added after that. My code: https://code.sololearn.com/cK0F4QpjmDpd/?ref=app

27th Apr 2020, 1:32 AM
David Giménez
David Giménez - avatar
4 Respuestas
0
# you could shorten it, by using list comprehension and do all stuff in oneliner: print(" ".join(palabra[1:] + palabra[0] + "ay" for palabra in input().split()))
27th Apr 2020, 4:21 AM
visph
visph - avatar
0
s=input("") q=s.split(' ') b=[i[1:]+i[0]+"ay" for i in q] print(*b)
27th Apr 2020, 6:09 AM
ANJALI SAHU
0
This is what I have coded for this problem in C programming....This programming executed successfully.... Hope this would help u.... C programming #include <stdio.h> #include<string.h> int main() { char a[100]; fgets(a,100,stdin); int i=0,j=0,d=0,e=0; while(a[i]!='\0') { for(j=0;j<=strlen(a);j++) { if(a[i]==a[j]) { d++; } } if(d>=2) { printf("Deja Vu"); e=1; break; } d=0; i++; } if(e==0) { printf("Unique \n"); } return 0; } All the cases ran successfully.... https://www.sololearn.com/Profile/21558748/?ref=app
17th Apr 2021, 5:07 AM
Shobha Kumari
Shobha Kumari - avatar
0
Using java# Solution it's work as well: import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String txt = scan.nextLine(); char startChar = txt.charAt(0); for(String i: txt.split(" ")){ System.out.print(i.substring(1)+i.charAt(0)+"ay"+" "); } } }
18th Jan 2022, 12:07 AM
Moussa Diallo
Moussa Diallo - avatar