1 条题解
-
0
C :
#include<stdio.h> #include<string.h> void main() { char a[1100]; while(gets(a)) { int i,j,k,l,m=0,n=0,b[1100]; for(i=0; i<strlen(a); i++) { if(a[i]!=' '&&a[i]!='.') n++; if(a[i]==' '||a[i]=='.') { i++; while(a[i]==' ') { i++; } m++; i--; if(m==1) printf("%d",n); else printf(" %d",n); n=0; } } printf("\n"); } }
C++ :
#include <stdio.h> #include <string.h> int main(){ char str[1000]; // 用来读取整个字符串 char *pStr; // 一个字符指针,用来存储以空格和点号分割的字符串 while(gets(str)){ pStr = strtok(str, " ."); // 先用空格和点号作一次切割 int iCount = 0; // 记录已经有多少数字输出了,由于每个数字间用一个空格分开,因而需要记录数字的输出数目 while(pStr){ if(iCount++){ putchar(' '); // 数字间使用一个空格分割 } printf("%d", strlen(pStr)); // 输出单词的长度 pStr = strtok(NULL, " ."); // 做下一次分割 } putchar('\n'); // 别忘了换行 } return 0; }
Pascal :
var a:ansistring; begin while not eof do begin readln(a); while pos(' ',a)<>0 do begin write(pos(' ',a)-1,' '); delete(a,1,pos(' ',a)) end; writeln(length(a)-1) end end.
Java :
import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner a=new Scanner(System.in); while(a.hasNextLine()){ String t=a.nextLine(); String u=""; String[] w=t.split(" "); int N=w.length; for(int i=0;i<N;i++){ if(i==N-1){ u=u+((w[i].length())-1); } else{ u=u+w[i].length()+" "; } } System.out.println(u); } } }
Python :
while True: lst = raw_input().replace('.','').split() for i in lst[0:-1]: print len(i), print len(lst[-1])
- 1
信息
- ID
- 1736
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者