首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

字符串字符个数统计解决方法

2012-04-14 
字符串字符个数统计#includeiostreamusing namespace stdvoid main(){char ch,str1[30]int i 0,j 0

字符串字符个数统计
#include<iostream>
using namespace std;
void main()
{
char ch,str1[30];
int i = 0,j =0, len,value = 0;
cout << "input the string:" << endl;
cin >> str1;
len = strlen(str1);
ch = str1[i];
while(ch != '\0')
{
while(j < len)
{
if(ch = str1[j])
value++;
j++;
}
cout << "the number of "<<ch<< "is:"<<value<<endl;
ch = str1[++i];
}
}


[解决办法]
看不懂,你在做啥?有啥问题?
[解决办法]

C/C++ code
#include<iostream>using namespace std;void main(){char ch,str1[30]={0};int i = 0,j =0, len,value = 0;cout << "input the string:" << endl;cin.getline(str1,30);len = strlen(str1);ch = str1[i];while(ch != '\0'){while(j < len){if(ch = str1[j])value++;j++;}cout << "the number of "<<ch<< "is:"<<value<<endl;ch = str1[++i];}}
[解决办法]
[code=C/C++][/code]
#include<iostream>
using namespace std;
void main()
{
char ch,str1[30]={0};
int i = 0,j =0, len,value = 0;
cout << "input the string:" << endl;
cin.getline(str1,30);
len = strlen(str1);
ch = str1[i];
while(ch != '\0')
{
while(j < len)
{
if(ch == str1[j]) //这里是==
value++;
j++;
}
cout << "the number of "<<ch<<" is:"<<value<<endl;
ch = str1[++i];
j=0;
value=0;
}
}

[解决办法]
C/C++ code
#include<iostream>using namespace std;void main(){    char ch,str1[30]={0};    int i = 0,j =0, len,value = 0;    cout << "input the string:" << endl;    cin.getline(str1,30);    len = strlen(str1);    ch = str1[i];    while(ch != '\0')    {        while(j < len)        {        if(ch == str1[j])    //这里是==            value++;        j++;        }    cout << "the number of "<<ch<<" is:"<<value<<endl;    ch = str1[++i];    j=0;    value=0;    }} 

热点排行