NYOJ1112求次数

题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=1112


用set水了好几遍才过的。。。


#include <string>
#include <iostream>
#include <set>
#include <cstdio>
using namespace std;

set<string> st;

int main()

{
    int t;
    scanf("%d",&t);
        while(t--)
        {
            int ans = 0;
            string s;
            int n;
            scanf("%d",&n);
            cin >> s;
            int len = st.size();
            for(int i = 0; i <= s.length() - n; ++i)
            {
                string te = s.substr(i,n);
                st.insert(te);
                if(len == st.size())
                    ans++;
                else len = st.size();
            }
            printf("%d\n",ans);
            st.clear();
        }
}

你可能感兴趣的:(字符串,set,ACM,STL)