这就是源代码。#include<stdio.h>
#include<time.h>
#include<stdlib.h>
main()
{
int i,j,lep,leg;
int count=0;
int nut=0;
char ch;
char str[7][10]={"abcdefghi","jklmnopqr","stuvwxyz","ABCDEFGHI","JKLMNOPQR","STUVWXYZ0","123456789"};
srand((unsigned)time(NULL));
for(i=0;i<7;i++)
{
for(j=0;j<10;j++)
{
lep=rand()%10;
leg=rand()%7;
ch=str[i][lep];
str[i][lep]=str[leg][j];
str[leg][j]=ch;
}
}
while(1)
{
nut=0;
while(1)
{
lep=rand()%10;
leg=rand()%7;
if(str[leg][lep]!=' ' && str[leg][lep]!='\0') /*系统会在每个字符串后自动添加 \0 */
{
printf("%c",str[leg][lep]); /*因为前面的字符串数组在交换时 \0 也会参与交换 */
nut++; /*在输出时不会显示,因此输出时加以限制输出,以满足条件 */
}
if(nut==4)break;
}
++count;
if(count!=4)
{
printf("-");
}
if(count==4)
{
break;
}
}
printf("\n");
}
|