Home > other >  Python statistics in the input Spaces, tabs, and carriage return number
Python statistics in the input Spaces, tabs, and carriage return number

Time:09-25

[problem description] respectively in statistical standard input Spaces, tabs, and carriage returns the number of (input end with Ctrl -z),
[form] input read from standard input characters, can include any character, the input end with Ctrl -z,
[form] output respectively output input characters, Spaces, tabs, and carriage returns the number of, with a space between the adjacent Numbers, no Spaces at the end of the output,
[sample input] C lanuage is very important. The HAHAHAHAHAA...
HAHAHAHAHAH
HAHAHA
[sample output] 4 3 3
[example] there are four Spaces in the string, three tabs (note here behind the important period and there are three tabs between HAHAHAHAHAA, but shown here is not clear that), and three carriage returns, so the output 4 3 3
Method a
Def the count (s) :
Count_a=count_z=count_s=0
For I in s:
If word (I)==32:
Count_a=count_a + 1
Elif word (I)==9:
Count_z=count_z + 1
Elif word (I)==10:
Count_s=count_s + 1
Print (count_a count_z, count_s)
If __name__=="__main__" :
S=input ()
The count (s)
Method 2
TmpStr=input ()
Letter=0
TAB=0
Enter=0
For I in tmpStr:
If (I==") :
Letter +=1
Elif (I=='\ t') :
TAB +=1
Elif (I=='\ n') :
Enter +=1
Print (letter, TAB, enter)

Is only the last two test points for bosses to solve