跳过正文
  1. Posts/

c++11 学习笔记

·1 分钟
目录

昨天终于搞定了ycm对c++11的支持….

嘛,17都快出来了,我竟然连11都不会用。

不过突然把所有的11特性给我也没办法全部吸收。

所以在这里记录下用过的c++11的用法。

#
auto可以代替stl的一些容器中的iterator:
#
1/******************************************************************
2*******************************************************************
3******************************************************************/
4set<int>se;
5//之前的写法遍历要这样写:
6for (set<int>::iterator it = se.begin() ;it!=se.end() ;it++)
7
8//用auto可以简化成这样子
9for ( auto it = se.begin(); it!=se.end() ;it++)

相关文章

c语言中static的作用

·1 分钟
一般有两个 1static int a; 2int b; 3void func(void) 4{ 5 static int c=0; 6 int d; 7} 在这里,a与b都是全局变量,二者的区别是,b可以被别的文件使用,a只能在本文件中使用,这是static对全局变量的作用。 ** c和d的区别是,d是一个自动变量,func函数执行完后,d会自动被释放。但c却不会被释放,下一次调用func函数时,c的值会保留上次的值继续使用(而不是初始值0,初始化只会在函数第一次被调用的时候执行)**

ac自动机模板by Lalatina (hdu 2222)

·1 分钟
orzorz 日常%学弟 华科的未来orz 1#include <cstdio> 2#include <cstring> 3 4using namespace std; 5 6struct tnode { 7 int s; 8 tnode *f, *w, *c[26]; 9} T[5000000], *Q[5000000]; 10int C; 11 12inline tnode *tnew() { 13 memset(T + C, 0, sizeof(tnode)); 14 return T + C++; 15} 16 17inline void AcaInsert(tnode *p, const char *s) { 18 while (*s) { 19 int u = *s - 'a'; 20 if (!p->c[u]) 21 p->c[u] = tnew(); 22 p = p->c[u]; 23 ++s; 24 } 25 ++p->s; 26} 27 28inline void AcaBuild(tnode *p) { 29 p->f = p->w = p; 30 int ql = 0; 31 for (int i = 0; i < 26; ++i) 32 if (p->c[i]) { 33 p->c[i]->f = p->c[i]->w = p; 34 Q[ql++] = p->c[i]; 35 } 36 for (int qf = 0; qf < ql; ++qf) 37 for (int i = 0; i < 26; ++i) 38 if (Q[qf]->c[i]) { 39 tnode *f = Q[qf]->f; 40 while (f != p && !f->c[i]) 41 f = f->f; 42 if (f->c[i]) { 43 Q[qf]->c[i]->f = f->c[i]; 44 Q[qf]->c[i]->w = f->c[i]->s ? f->c[i] : f->c[i]->w; 45 } 46 else 47 Q[qf]->c[i]->f = Q[qf]->c[i]->w = p; 48 Q[ql++] = Q[qf]->c[i]; 49 } 50} 51 52inline int AcaMatch(tnode *root, const char *s) { 53 int x = 0; 54 for (tnode *p = root; *s; ++s) { 55 while (p != root && !p->c[*s - 'a']) 56 p = p->f; 57 if (p->c[*s - 'a']) { 58 p = p->c[*s - 'a']; 59 for (tnode *q = p; q->s != -1; q = q->w) { 60 x += q->s; 61 q->s = -1; 62 } 63 } 64 } 65 return x; 66} 67 68char S[1000001]; 69 70int main() { 71 int tt; 72 scanf("%d", &tt); 73 while (tt--) { 74 C = 0; 75 tnode *root = tnew(); 76 root->s = -1; 77 int N; 78 scanf("%d", &N); 79 while (N--) { 80 scanf("%s", S); 81 AcaInsert(root, S); 82 } 83 AcaBuild(root); 84 scanf("%s", S); 85 printf("%d\n", AcaMatch(root, S)); 86 } 87 return 0; 88}