1 条题解
-
0
C :
#include <stdio.h> int main() { int character = 1, i; char a[100]; gets(a); for (i = 0;a[i] != '\0';i++) if (' ' == a[i]) character++; printf("%d\n", character); }
C++ :
#include<iostream> using namespace std; char s[101]; int main() { cin.getline(s,101); char c; int num=0,word=0; for (int i=0; (c=s[i])!='\0'; i++) if (c==' ') word=0; else if (word==0) { num++; word=1; } cout<<num<<endl; return 0; }
Java :
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()){ String s=sc.nextLine(); int n=1; for(int i=0;i<s.length();i++){ if(s.substring(i, i+1).matches(" ")){ n++; } } System.out.println(n); } sc.close(); } }
- 1
信息
- ID
- 1752
- 时间
- 1000ms
- 内存
- 12MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者