70,037
社区成员
发帖
与我相关
我的任务
分享#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define RANDCHAR (rand() % 26 + 'a')
#define CHARINDEX(c) (((unsigned)(unsigned char)(c - 'a')) % 26)
void main(void){
// 查表判断 at,is,he,up,on,we
const char flags[] = {'t', 0, 0, 0, 0, 0, 0, 'e', 's', 0, 0, 0, 0, 0, 'n', 0, 0, 0, 0, 0, 'p', 0, 'e', 0, 0, 0};
char c, lc;
signed count;
srand((unsigned)time(NULL));
printf("%d\n", CHARINDEX('b'));
for(count = 0, c = RANDCHAR, lc = 'b'; flags[CHARINDEX(lc)] != c; lc = c, c = RANDCHAR, count++){
if(count < 0)break;
}
printf("\n\nTotal : %d\n", count);
}
#include <stdlib.h>
#include <iostream>
#include <time.h>
using namespace std;
int main()
{
int i = 0;
char pre = ' ';
char now = ' ';
int n = 0;
srand( (unsigned)time( NULL ) );
while (1)
{
i = rand() % 26;
pre = now;
now = (char) (i + 97);
printf("%c", now);
if ((pre == 'a' && now == 't')
|| (pre == 'i' && now == 's')
|| (pre == 'h' && now == 'e')
|| (pre == 'u' && now == 'p')
|| (pre == 'o' && now == 'n')
|| (pre == 'w' && now == 'e'))
{
break;
}
n++;
}
printf("\ncharacters: %d\n", n);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define MAKE_WORD(a, b) (((a)-'a')*26+(b)-'a')
int main()
{
int a, b;
int dest[]={MAKE_WORD('a','t'), MAKE_WORD('i','s'), MAKE_WORD('h','e'),
MAKE_WORD('u','p'),MAKE_WORD('o','n'), MAKE_WORD('w','e')};
char* stb[]={"at","is","he","up","on","we"};
int i, flag = 1, n = 0;
srand(time(NULL));
while (flag)
{
a = rand()%26, b = rand()%26;
++n;
printf("%c%c\n", (a&0xff)+'a', (b&0xff)+'a');
for (int i = 0, it = a*26+b; i < sizeof(dest)/sizeof(dest[0]); ++i)
if (dest[i] == it)
{
flag = 0;
break;
}
}
printf("%d\n", n);
return 0;
}