NYOJ1112求次数

来源:互联网 发布:java做界面的工具 编辑:程序博客网 时间:2024/05/29 10:09

题目链接: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();        }}

0 0
原创粉丝点击