64,654
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <fstream>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int main()
{
/*读取文档为字符串,计算文档长度,将字符串转为数组*/
fstream fileintput;
fileintput.open("D://rdy.txt",ios::in);
char a;
string s = "";
int i=1;
while(1){
fileintput>>a;
if(fileintput.eof())
break;
s.push_back(a);
}
fileintput.close();
cout << s.length() << endl;
char ch[400000];
strcpy(ch,s.c_str());
for (i=0;i<400000;i++)
{
if(ch[i]=='\0'){
cout << i << endl;
break;
}
}
/***********************************************/
char x[9][11];
/************分割数组并赋给二维数组*************/
const char * split = ">1234567890";
char * p;
p = strtok (ch,split);
int k=0;
while(p!=NULL)
{
cout<<k<<endl;
printf ("%s\n",p);
p = strtok(NULL,split);
x[k][0]= *p;
k++;
}
/*********************************************/
/*****打印二维数组(测试数组赋值成功)******/
cout<<1111111<<endl;
int l,h;
for(l=0 ; l<10 ; l++)
{
for(h=0 ; h<12 ; h++)
printf("%d",x[l][h]);
cout<<l<<endl;
}
cout<<2222222<<endl;
/********************************************/
return 0;
}
/*****************编辑距离函数********************/
/*
int edit(string str1, string str2)
{
int max1 = str1.size();
int max2 = str2.size();
int **ptr = new int*[max1 + 1];
for(int i = 0; i < max1 + 1 ;i++)
{
ptr[i] = new int[max2 + 1];
}
for(int i = 0 ;i < max1 + 1 ;i++)
{
ptr[i][0] = i;
}
for(int i = 0 ;i < max2 + 1;i++)
{
ptr[0][i] = i;
}
for(int i = 1 ;i < max1 + 1 ;i++)
{
for(int j = 1 ;j< max2 + 1; j++)
{
int d;
int temp = min(ptr[i-1][j] + 1, ptr[i][j-1] + 1);
if(str1[i-1] == str2[j-1])
{
d = 0 ;
}
else
{
d = 1 ;
}
ptr[i][j] = min(temp, ptr[i-1][j-1] + d);
}
}
int dis = ptr[max1][max2];
for(int i = 0; i < max1 + 1; i++)
{
delete[] ptr[i];
ptr[i] = NULL;
}
delete[] ptr;
ptr = NULL;
/****************输出结果(a b 结果 时间)****************/
// cout<< << << << ;
/*********************************************************/
// return dis;
//}
/*********************************************************/