它总是出来0和0,我只是试图计算用户给出的字符串中的Gs和Cs(以及非G和Cs)。我知道这是一个初学者的问题,我们对此深感抱歉:(不能计算字符串中的字符数
#include <iostream>
#include <string>
using namespace std;
int main()
{
int x = 0
int y = 0
string s;
cout << "Enter a sequence" << endl;
cin >> s;
for (int i = 0; i > 100; i++)
if (s[i] == 'g' || s[i] == 'c')
x += 1;
else
y += 1;
cout << x << endl;
cout << y << endl;
}
有一个这样的算法:'std :: count_if'。 – chris
请提供一个输入和输出的例子。 –
@chris哈!不是这次:P –