|
| » 首页 » 电脑_数码 » 编程 » 设计c++程序计算字符串s中包含字母数量大于n的单词个数 |
设计c++程序计算字符串s中包含字母数量大于n的单词个数 |
|
|
![]() |
|
|
a,i,max,min:longint; begin max:=-maxlongint; min:=maxlongint; for i:=1 to 10 do begin read(a); if a<min then min:=a; if a>max then max:=a; end; writeln(min,' ',max); end. #include<fstream.h> #define N 50 int alpha(char c){//判断一个字符是否为字母 if(c>='a'&&c<='z')return 1; if(c>='A'&&c<='Z')return 1; else return 0; } void main(){ int i,n,k,num=0; char s[N]; cout<<"请输入字符串s"<<endl; cin.getline(s,N);//连空格一起接收N个字符,当作字符串s cout<<"n="; cin>>n; for(i=0;i<N&&s[i]!='{answer}';i++){ if(alpha(s[i])){ for(k=0;alpha(s[i]);i++,k++);//找到字母开头的串则查看这个字母串的长度k if(k>n)num++;//串长度大于等于n,计数器+1 } } cout<<"字母数量大于n的单词个数为"<<num<<"个"<<endl; } |
| 《设计c++程序计算字符串s中包含字母数量大于n的单词个数》答案收集时间:2008-06-14 14:38:37 |