VC驿站

 找回密码
 加入驿站

QQ登录

只需一步,快速开始

搜索
查看: 541|回复: 0

大佬们,过来看看啊!为什么这段代码在VC6能运行,而在VC2008上不能运行呢?

[复制链接]
38_avatar_middle
最佳答案
0 
在线会员 发表于 2020-9-14 19:02:48 | 显示全部楼层 |阅读模式
大佬们,过来看看啊!为什么以下代码在VC6能运行,而在VC2008上不能运行呢?
//Index_KMP.cpp

#include <stdio.h>
#include <conio.h>
#include <iostream>
#define MAXSTRLEN 255
using namespace std;
typedef unsigned char SString[MAXSTRLEN+1];                    //from 0 to 256 becoz of '\0'
int next[MAXSTRLEN+1];

void get_next(SString T,int *next)                             //get_next() function
{// get the next value and save into array next,be ready for matching
        int        i=1,j=0;
        next[1]=0;                                                 //set Init_values
    while(i<=T[0])
        {   if(j==0||T[i]==T[j])
           { ++i;++j;
             next[i]=j;
                }//end of if
           else j=next[j];                                         //if j!=0 or T[k]!=T[j] then j=next[j]
        }//end of while
}//end of get_next


int Index_KMP(SString S,SString T,int pos)                     //Index_KMP() function
{ //S[0] and T[0] are the length of SString
  //use the "next" function to get the position of where the T is in main SString from pos on
  //1<=pos<=S[0]-T[0]+1
    int i=pos,j=1;                                             //set Init_values
        while(i<=S[0]&&j<=T[0])
                {if (j==0||S[i]==T[j])
                        {++i;
                 ++j;
                        }//end of if
             else
                         j=next[j];
                }//end of while
        if(j>T[0]) return (i-T[0]);
        else return (0);
}//end of Index_KMP

   
void main()                                                      //main() function
{
   SString S,T;
   int pos;                                                      //  1<=pos<=S[0]-T[0]+1;
   int m,n,r;                                                    //  the length of SString S and T
   cout<<"Index_KMP.cpp"<<endl<<"============="<<endl<<endl;
   cout<<"Please input the Main SString S: <eg. Beijing> ";
   cin.getline(S+1,MAXSTRLEN);
   cout<<"Please input the other SString T: <eg. jing> ";
   cin.getline(T+1,MAXSTRLEN);
   cout<<"From ... on?: ";
   cin>>pos;

   for(m=0;S[m]!='\0';m++);                                      // get the length of SString S
   S[0]=m-1;
   for(n=0;T[n]!='\0';n++);                                      // get the length of SString T
   T[0]=n-1;

   get_next(T,next);

   if(r=Index_KMP(S,T,pos))                                
          cout<<"The postion of T in the Main SString S from "<<pos<<" chars on is: "<<r<<endl<<"...OK!..."<<endl;
   else cout<<"Failure to Index the SString!"<<endl;
   getch();
}//end of main() function




上一篇:webbrower控件疑问
下一篇:自己建一个对话框里面的控件变量找不到
您需要登录后才可以回帖 登录 | 加入驿站 qq_login

本版积分规则

×【发帖 友情提示】
1、请回复有意义的内容,请勿恶意灌水;
2、纯数字、字母、表情等无意义的内容系统将自动删除;
3、若正常回复后帖子被自动删除,为系统误删的情况,请重新回复其他正常内容或等待管理员审核通过后会自动发布;
4、感谢您对VC驿站一如既往的支持,谢谢合作!

关闭

站长提醒上一条 /2 下一条

QQ|小黑屋|手机版|VC驿站 ( 辽ICP备09019393号-4 )|网站地图wx_jqr

GMT+8, 2023-12-10 08:04

Powered by CcTry.CoM

© 2009-2021 cctry.com

快速回复 返回顶部 返回列表