【C++】STL String

C++提供String 的模板类,可以很方便的处理字符串。

#include <iostream>
using namespace std;


class Solution {
public:
    
    int countPrimes(int n) {
        int count=0;
int i=0;
int t=0;
cout <<"n="<<n<<endl;
        if (n==0 || n==1)
            count=0;
        else
        {
        for(i=2; i<=n; i++)
        {
            for (t=2; t*t<i;t++)
                if (i%t==0)
cout<<i<<"is zhishu"<<endl;
//缺少break
                    count+=1;
        }
        }
        return count;
    }
};


int main()
{
    Solution test;
test.countPrimes(10);
cout << test.countPrimes(10);
   return 0;
}

猜你喜欢

转载自blog.csdn.net/onlyongwang/article/details/80909235