C++简单字符串问题。。
大大能不能再问你一个问题呀。。。今晚的DDL我怎么也DEBUG不出来啊T.T。。。#include"stdafx.h"#include<iostream>#include...
大大能不能再问你一个问题呀。。。今晚的DDL我怎么也DEBUG不出来啊T.T。。。
#include"stdafx.h"
#include<iostream>
#include<string>
using namespace std;
int main(){
int aver,total=0,l=0,i;
string a;
cout<<"Please input the string:"<<endl;
getline(cin,a,'.');
for(i=0;a[i]!='.';i++)
if(((a[i]>='a'&&a[i]<='z')||(a[i]>='A'&&a[i]<='Z'))&&!((a[i+1]>='a'&&a[i+1]<='z')||(a[i+1]>='A'&&a[i+1]<='Z')))
total++;
for(i=0;a[i]!='.';i++)
if((a[i]>='a'&&a[i]<='z')||(a[i]>='A'&&a[i]<='Z'))
l++;
aver=l/total;
cout<<"The avarage length of the string is "<<aver<<endl;
return 0;
}
求助啊。。。。谢谢你!!! 展开
#include"stdafx.h"
#include<iostream>
#include<string>
using namespace std;
int main(){
int aver,total=0,l=0,i;
string a;
cout<<"Please input the string:"<<endl;
getline(cin,a,'.');
for(i=0;a[i]!='.';i++)
if(((a[i]>='a'&&a[i]<='z')||(a[i]>='A'&&a[i]<='Z'))&&!((a[i+1]>='a'&&a[i+1]<='z')||(a[i+1]>='A'&&a[i+1]<='Z')))
total++;
for(i=0;a[i]!='.';i++)
if((a[i]>='a'&&a[i]<='z')||(a[i]>='A'&&a[i]<='Z'))
l++;
aver=l/total;
cout<<"The avarage length of the string is "<<aver<<endl;
return 0;
}
求助啊。。。。谢谢你!!! 展开
1个回答
展开全部
#include<iostream>
#include<string>
using namespace std;
int main(){
int aver, total = 0, l = 0, i;
string a;
cout << "Please input the string:" << endl;
getline(cin, a, '.');
for (i = 0;i< a.length()-1 ; i++)//a[i] != '.'这里错误
if (((a[i] >= 'a'&&a[i] <= 'z') || (a[i] >= 'A'&&a[i] <= 'Z')) && !((a[i + 1] >= 'a'&&a[i + 1] <= 'z') || (a[i + 1] >= 'A'&&a[i + 1] <= 'Z')))
total++;
for (i = 0; i< a.length(); i++)
if ((a[i] >= 'a'&&a[i] <= 'z') || (a[i] >= 'A'&&a[i] <= 'Z'))
l++;
aver = l / total;
cout << "The avarage length of the string is " << aver << endl;
return 0;
}
#include<string>
using namespace std;
int main(){
int aver, total = 0, l = 0, i;
string a;
cout << "Please input the string:" << endl;
getline(cin, a, '.');
for (i = 0;i< a.length()-1 ; i++)//a[i] != '.'这里错误
if (((a[i] >= 'a'&&a[i] <= 'z') || (a[i] >= 'A'&&a[i] <= 'Z')) && !((a[i + 1] >= 'a'&&a[i + 1] <= 'z') || (a[i + 1] >= 'A'&&a[i + 1] <= 'Z')))
total++;
for (i = 0; i< a.length(); i++)
if ((a[i] >= 'a'&&a[i] <= 'z') || (a[i] >= 'A'&&a[i] <= 'Z'))
l++;
aver = l / total;
cout << "The avarage length of the string is " << aver << endl;
return 0;
}
更多追问追答
追问
谢谢大大!!如果我想输出某句子的平均单词长度,应该怎么改呢。。?
追答
aver你不是求了么
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询