+ 69
CHALLENGE: Counting And Display Strings
Write a program that captures a string that can contain spaces and displays each word in the string, the separator being the space. Example, for the input: "I think so I am" The program displays: word 1: I word 2: think word 3: so word 4: I word 5: am And finally it shows how many words the sentence has. Good luck.
109 Antworten
+ 39
@med Nice basic challenge thank you
pythonistas take it easy
https://code.sololearn.com/cKb3je99nnwL/?ref=app
+ 37
Splitting using java8
https://code.sololearn.com/cq87UW48d3RF/?ref=app
+ 33
https://code.sololearn.com/c5R1Oi6UVfB4/?ref=app
+ 22
My try with C++:
https://code.sololearn.com/cqjCVSMPVROt/?ref=app
+ 20
https://code.sololearn.com/c3wz3rzJMHOD/?ref=app
+ 18
A little bit of Ruby:
* https://code.sololearn.com/co2J86RSE65p/#rb
+ 18
Python is great at string manipulation d:
https://code.sololearn.com/cG4H4S85Gb40/?ref=app
I was also able to make it in Ruby :D
https://code.sololearn.com/csS7C2E0VP00/#rb
And also Java :p
https://code.sololearn.com/c9pg0Z7L73wO#java
One more in JavaScript :)
https://code.sololearn.com/WqLLO1mj7BQP/?ref=app
Last one in C#
https://code.sololearn.com/cnTfhkEX26Ky/?ref=app
+ 16
// JS Solution
let words = prompt("Enter something", "I think so I am").split(" ");
for(var i = 0; i < words.length; i++) {
document.write(`word ${i+1}: ${words[i]}<br />`);
}
document.write("<br />You have entered ", i, " words!");
+ 16
Slowly I start to think you can do everything in one line in python
https://code.sololearn.com/c2EqFC663P7o/#py
+ 16
https://code.sololearn.com/coTnqYEGTIeE/?ref=app
+ 13
+ 13
Here's mine in python:
https://code.sololearn.com/cVHAnmcm5B9b/?ref=app
+ 11
+ 11
My solution: Can handle multiple consecutive spaces.
https://code.sololearn.com/WwrZS8v3IKDq/?ref=app
+ 11
https://code.sololearn.com/cXJAx2Tx5rRr/?ref=app
+ 11
https://code.sololearn.com/cKadiV9kgC4M/?ref=app
+ 10
+ 10
Working now! thanks @Jonathan Pizarra
https://code.sololearn.com/WYSEJr7k12KM/?ref=app