Redaksiya
Read the text word by word using the scanf function with the "%s" format. Determine the length of the word using the strlen function.
When using the C++ language, read words into string type variables using the cin function. Use the size method to find the length of the word.
Algorithm realization
Read the word into array .
char s[100];
Read the text word by word until the end of the file. For each word print its length.
while(scanf("%s",s) == 1) printf("%d ",strlen(s));
Algorithm realization — C++
Read the text word by word until the end of the file. For each word print its length.
while (cin >> s) cout << s.size() << " "; cout << endl;
Java realization
import java.util.*; public class Main { public static void main(String[] args) { Scanner con = new Scanner(System.in); while(con.hasNext()) { String s = con.next(); System.out.print(s.length() + " "); } con.close(); } }
Python realization
Read the text line by line until the end of the file.
import sys for x in sys.stdin: x = x.split()
The variable contains a list of words from one line.
for i in x:
For each word from the list print its length. The lengths of the words are printed on one line, separated by a single space.
print(len(i), end = ' ')