/* test1.c 文字列照合 */
#include <stdio.h$>
#include <stdlib.h>
#include "match.h"
void init_ornd0(long seed);
double ornd0(void);
int irnd(int max, int min);
#define MASK 123459876L /* 初期化マスク(任意定数)*/
long _idum_o0; /* ornd0()の乱数核 */
double (*_rand)(void); /* irnd()で呼び出す一様分布乱数 */
main()
{
unsigned char *string, *p;
int m = 240, n;
string = (unsigned char *)malloc((m + 1) * sizeof(unsigned char));
init_ornd0(1L);
p = string + m;
*p-- = '\0';
while(p >= string) *p-- = irnd('z', 'a');
p = string + m - 1;
while(1)
{
n = irnd(10, 1);
while(n--) p--;
if(p <= string) break;
*p-- = ' ';
}
printf("%s\n", string);
printf("bm(string, \"abc\") = %d\n", bm(string, "abc"));
printf("bm(string, \"tt\") = %d\n", bm(string, "tt"));
printf("bm(string, \"izs\") = %d\n", bm(string, "izs"));
return 1;
}
void init_ornd0(long seed)
{
_idum_o0 = seed ^ MASK;
}
double ornd0(void) /* Park and Miller の「最低基準」乱数 */
{
long w;
double d = 1. / 2147483647.;
w = _idum_o0 / 127773L;
if((_idum_o0 = (_idum_o0 - w * 127773L) * 16807 - w * 2836) <= 0)
_idum_o0 += 2147483647L;
return (double)_idum_o0 * d;
}
int irnd(int max, int min)
{
return min + (int)(ornd0() * (double)(max - min + 1));
}
|