| 查看: 1018 | 回复: 6 | ||
[交流]
顺序串kmp无回溯算法 大神进来指导一下
|
||
|
void SqString::get_next(int* next, int display) { int j=-1,i=0; int first_i; char no[5]=" [ i]"; next[0[=-1; while(i if(j==-1||ch[j]=ch) { ++j; ++i; next=j; } else j=next[j]; } if(display==1) { cout<<" 当前模式串的next[]数组为:"< while(first_i i=first_i; cout<<" "; do { if(i<10) no[2]=i+"0"; (这是什么意思) else { no[1]=i/10+"0"; no[2]=i%10="0"; } cout.width(5); cout.fill("" ;cout.setf(ios::right,ios::adjustfileld); cout< } while(i%10&&i cout<<" "; i=first_i; do { cout.width(5); cout.fill("" ;cout.setf(ios::right,ios::adjustfileld); cout< i++; } while(i%10&&i cout<<" "; i=first_i; do { cout.width(5); cout.fill("" ;cout.setf(ios::right,ios::adjustfileld); cout< i++; } while(i%10&&i cout< } } 这是主要的求next数组的 看不懂啊。。。。。。。请指点 |
2楼2012-11-01 22:40:26
3楼2012-11-02 11:38:13
4楼2012-11-02 11:39:34
★ ★ ★ ★ ★ ★
小木虫: 金币+0.5, 给个红包,谢谢回帖
断点~+++: 金币+5 2012-11-03 15:08:23
小木虫: 金币+0.5, 给个红包,谢谢回帖
断点~+++: 金币+5 2012-11-03 15:08:23
|
定义no是个字符数组 而char又可以跟short,int等类型进行转换,具体分为signed和unsigned: 然后看这句: 我比较怀疑是不是抄错了,应该是单引号'0'而不是双引号?单引号'0'表示0这个字符,然后i是整型,2个相加等于下面的过程 '0'先被转为整型,与i相加,然后再转为char类型存入no数组的第三个位置 因为既然'0'表示0的int值,那么i+'0'当i在0-9之间取值时,i+'0'的结果就是'0'到'9'这10个字符 那么下面的代码就是: 如果i小于10,将i对应的个位数转为对应的字符存入no数组第三个位置 否则,将两位数i转为对应的字符,分别存入no数组的第二和第三个位置 不过,数字转为对应字符串(例如20转为"20" 一般建议2种做法,一个是itoa()函数,另一个标准做法是sprintf()函数 |
5楼2012-11-02 17:09:37
7楼2012-11-03 15:08:07
简单回复
su-b086楼
2012-11-02 21:17
回复










;
回复此楼