// 属于原创代码,供大家学习交流。
// 此代码实现了严蔚敏版的数据结构中三元组的代码!
#include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int Status;
typedef int ElemType;
typedef ElemType *Triplet;
Status InitTriplet(Triplet &T)
{
ElemType v1, v2, v3;
T=(ElemType *)malloc(3*sizeof(ElemType));
if (!T)
{
exit(OVERFLOW);
}
scanf("%d%d%d",&v1,&v2,&v3);
T[0]=v1,T[1]=v2,T[2]=v3;
return OK;
}
编写函数int find(char s[],char t[])在字符串s中查找字符串t,如果找到,则返回字符串t在字符串s中的位置。
#include <iostream.h>
#include <string.h>
int find(char
s[],char t[]);
const int MAX=256;
int main()
{
char
source[MAX],target[MAX];
cout<<"Please input a string for
searching:/n";
cin.getline(source,MAX);
cout<<"Please input
a string you want to find:/n";
cin.getline(target,MAX);
int
intPOs=find(source,target);
if (intPOs>=0)
{
cout<<"Finding it,The tagert string is at index"<<intPOs<<"of
the source string/n";
}
else
cout<<"Not finding
it/n";
return 0;
}