主题:帮个忙,在字符串中找重复的字符串的次数
找出]"TTT","TTH","THT","THH","HTT","HTH","HHT","HHH"在S1="HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH";
分别出现的次数,从S1的起始位置S1[0]到末S1[37]结束
#include<iostream>
#include<string>
using namespace std;
int main(){
string s[8][3]={"TTT","TTH","THT","THH","HTT","HTH","HHT","HHH"};
string S1="HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH";
int sum[8]={0};
for(int i=0;i<=7;i++){//s1,s2....分8次循环
for(int j=0;j<=37;j++){
if(S1[j]==s[i][0]&&S1[j+1]==s[i][1]&&S1[j+2]==s[i][2])
sum[i]++;
else ;
}
}
for(i=0;i<=7;i++){//这里我会改进,不需要找错误
cout<<i<<'\t'<<sum[i]<<endl;
}
return 0;
}
这是我写的,编译时出现问题,在if(S1[j]==s[i][0]&&S1[j+1]==s[i][1]&&S1[j+2]==s[i][2])
这一句;它是这样写的:cpp(12) : error C2677: binary '==' : no global operator defined which takes type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptab
le conversion)
分别出现的次数,从S1的起始位置S1[0]到末S1[37]结束
#include<iostream>
#include<string>
using namespace std;
int main(){
string s[8][3]={"TTT","TTH","THT","THH","HTT","HTH","HHT","HHH"};
string S1="HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH";
int sum[8]={0};
for(int i=0;i<=7;i++){//s1,s2....分8次循环
for(int j=0;j<=37;j++){
if(S1[j]==s[i][0]&&S1[j+1]==s[i][1]&&S1[j+2]==s[i][2])
sum[i]++;
else ;
}
}
for(i=0;i<=7;i++){//这里我会改进,不需要找错误
cout<<i<<'\t'<<sum[i]<<endl;
}
return 0;
}
这是我写的,编译时出现问题,在if(S1[j]==s[i][0]&&S1[j+1]==s[i][1]&&S1[j+2]==s[i][2])
这一句;它是这样写的:cpp(12) : error C2677: binary '==' : no global operator defined which takes type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptab
le conversion)