前置芝士 :string 的 基本用法

        string s = "hello world" ;
string tmp(s,0,5) ;
cout << tmp << endl ;

上面这一段代码 可以复制粘贴 然后改变 数字。(试试效果

\(string\ tmp(s,i,n);\)

赋初值 也就是说从 $s[i]\ - To - \ s[i+n-1] $

所以既然是这样 应该就有一种比较优秀的做法 \(O(S.length())\)

可海星。

\[STL大法好啊
\]

然后用\(map\)统计种类(\(set\)也行的。

#include <bits/stdc++.h>
#define rep(i,j,n) for(register int i=j;i<=n;i++)
#define Rep(i,j,n) for(register int i=j;i>=n;i--)
#define low(x) x&(-x)
using namespace std ;
typedef long long LL ;
const int inf = INT_MAX >> 1 ;
inline LL In() { LL res(0) , f(1) ; register char c ;
#define gc c = getchar()
while(isspace(gc)) ; c == '-' ? f = - 1 , gc : 0 ;
while(res = (res << 1) + (res << 3) + (c & 15) , isdigit(gc)) ;
return res * f ;
#undef gc
} int n ;
int c ;
string s ;
map < string , int > ans ;
inline void Ot() {
cin >> n >> c >> s ;
rep(i,1,s.length()-n+1) {
string tmp(s,i-1,n) ; // from i - 1 to (i - 1 + n -1 )
//if(tmp.length() < n) continue ;
ans[tmp] ++ ;
}
cout << ans.size() << endl ;
}
signed main() {
// freopen("test.in","r",stdin) ;
return Ot() , 0 ;
}
#include <bits/stdc++.h>
#define rep(i,j,n) for(register int i=j;i<=n;i++)
#define Rep(i,j,n) for(register int i=j;i>=n;i--)
#define low(x) x&(-x)
using namespace std ;
typedef long long LL ;
const int inf = INT_MAX >> 1 ;
inline LL In() { LL res(0) , f(1) ; register char c ;
#define gc c = getchar()
while(isspace(gc)) ; c == '-' ? f = - 1 , gc : 0 ;
while(res = (res << 1) + (res << 3) + (c & 15) , isdigit(gc)) ;
return res * f ;
#undef gc
} int n , c ;
string s ;
set < string > st ;
inline void Ot() {
cin >> n >> c >> s ;
rep(i,1,s.length()-n+1) {
string tmp(s,i-1,n) ;
st.insert(tmp) ;
}
cout << st.size() << endl ;
}
signed main() {
// freopen("test.in","r",stdin) ;
return Ot() , 0 ;
}

随机推荐

  1. 【状压+状态转移】A Famous Airport Managere

    https://www.bnuoj.com/v3/problem_show.php?pid=25653 [题意] 给定一个3*3的九宫格,模拟一个停机坪.第一个格子一定是'*',代表take off ...

  2. Codeforces700C. Break Up

    n<=1000,m<=30000的图,问割掉边权和尽量小的0.1或2条边使S和T不连通,输出割了哪些边,无解-1. 道理是很好懂的,先随便找S到T的一条路径,找不到输出0,找到的话这条路上 ...

  3. 【小记事】电脑命令行开WiFi

    1.设置WiFi名称和密码 在命令行输入: netsh wlan set hostednetwork mode=allow WiFi名称 key=密码 2.开启WiFi 在命令行输入: netsh w ...

  4. Sql查询一个列对应多个列

    Sql查询一个列对应多个列 今天遇到一个问题,表table1有两个字段col1.col2两个字段.先记录下来,以后有个参考. 现在需要查询出的数据满足如下要求: 1.col1重复.col2重复的数据只 ...

  5. linux network name space

    linux network namespace概念类似于网络中的 VRF (virtual routing and forwarding).但是,你不知道VRF的概念也没关系,下面我们通过一个简单的介 ...

  6. the apple code

    i know you will forget but 9 you will

  7. gcc 5.2.0 编译安装笔记-20151110

    **转载请注明出处** by.haunying3 系统版本号 CentOS-6.6-x86_64-minimal 编译器 gcc-4.4.7通过yum安装 rpm -qa | grep gcc gcc ...

  8. node-load module

    javscript :脚本建共享全局名称空间(全局污染). node:实现CommonJS(公共)模块标准. Node加载模块,有两种方式: 1.通过名称 除非是核心模块,否则被引用的模块最后都会映射 ...

  9. vux 全局使用 loading / toast / alert

    1.入口文件 main.js import { LoadingPlugin, ToastPlugin, AlertPlugin } from 'vux' Vue.use(LoadingPlugin); ...

  10. 字符串匹配之KMP算法(续)---还原next数组

    相信通过今天的文章,你会对KMP的认识更加深入一层,不止停留在知道怎样计算的层面上了,废话不多说,開始. 通过前面的第一篇文章,知道了怎么求next数组,相信非常多喜欢刨根问底的人就会问,我依照你的做 ...