借用excel吧。
把文章复制,粘贴到Excel中,这时候每一段都是一个单元格,形成轿扰了一列数据。
然后在B1列输入=rand(),向下拖,复制函数到此帆码最后一段文字,生产一个随森哪机数列
排序,按B列排序。
复制A列的内容,在Word里选择性粘贴,文本。
结果如下
另外说明,如果对结果不满意,只需要在Excel排序时重新排序就可以。
下面是用程序(C语言)将文章保存为d:\article.txt文件。 生成的打乱文件将在d:\new_art.txt
你如果没有编译器的话,你留下邮箱,我将生成团裤的exe文件发给你。
然后运行一下代码生成的可执行程序即可。
/*****************************************************************
*Author :wacs5
*Date :20081230(YYYYMMDD)
*Function :
* 打乱文章顺序(文章篇幅不多于8000字)
*input data :d:\article.txt
*output data :d:\new_art.txt
****************************************************************/
#include <time.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define MAXCHR 8000 /*最大处理8000个汉字*/
main()
{
char *text
int *loc,*flag
int i,count,readchr,rndord,temp
fpos_t filelen
FILE *fp,*fpout
srand((unsigned)time(NULL))
fp=fopen("d:\\article.txt","r")
fpout=fopen("d:\\new_art.txt","w")
if (fp==NULL)
{
printf("ERROR: File Open Error:\nPress any key to exit:")
getch()
exit(1)
}
fseek(fp,0,SEEK_END)/*reach the End of File*/
fgetpos(fp,&filelen)
if (filelen>携或唤MAXCHR)
{
printf("ERROR: The Article is too big:\nPress any key to exit:")
getch()
exit(1)
}
text=(char *) calloc(filelen+20,sizeof(char))
loc =(int *) calloc(filelen+20,sizeof(int ))
flag=(int *) calloc(filelen+20,sizeof(int ))
if (text==NULL || loc==NULL || flag==NULL)
{
printf("ERROR: No enough Memory:\nPress any key to exit:")
getch()
exit(1)
}
for (i=0i<fileleni++)
loc[i]=flag[i]=0
memset(text,'\0',filelen)
fseek(fp,0,SEEK_SET)/*Go to the beginning of the file*/
readchr=fread(text,sizeof(char),filelen,fp)
printf("filelen=%ld\nreadchr=%d\n",filelen,readchr)
i=0/*读text内容的序号*/
count=0/*文章中有多少个字(一个英文、一个汉字都算一个字)*/
while(i<readchr)
{
if (text[i]&0x80)
{
flag[count]=1 /*标记一下,这个位置为汉字*/
loc[count++]=i/*记住位置*/
i+=2
}
else
{
loc[count++]=i
i++
}
}
for (i=0i<counti++)
{
rndord=rand()%(count-i)
/*输辩凯出rndord的字(英文或中文)*/
if (flag[rndord])
fprintf(fpout,"%c%c",text[loc[rndord]],text[loc[rndord]+1])
else
fprintf(fpout,"%c",text[loc[rndord]])
temp=loc[count-i-1]
loc[count-i-1]=loc[rndord]
loc[rndord]=temp
temp=flag[count-i-1]
flag[count-i-1]=flag[rndord]
flag[rndord]=temp
}
free(text)
free(loc)
free(flag)
fclose(fp)
printf("OK\n")
getch()
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)