📄 123.txt
字号:
/* DNF.c
Copyright (c) 2002, 2006 by ctu_85
All Rights Reserved.
*/
#include "stdio.h"
#include "conio.h"
#include "string.h"
#define maxnum 12
int a[]={0,1,1,2,0,2,1,1,2,0,1,1};
enum {red,white,blue};
void Create(int);
void Display(int,int);
void DNF(int);
int main()
{
char *in;
int length=0;
textbackground(0);
clrscr();
re:
printf("Please enter the array:\n");
printf("press 1 to create a new array,2 to use the system example:");
scanf("%s",in);
length=strlen(in);
if(length>1||length==0||(*in!='1'&&*in!='2'))
{
printf("Error!\n");
goto re;
}
if(*in=='1')
{
scan:
printf("Please set the num of the array:");
scanf("%s",in);
if(strlen(in)==1)
length=*in-'0';
if(strlen(in)==2)
length=10*(*in-'0')+(*(in+1)-'0');
if(strlen(in)>2||length<1||length>maxnum)
{
printf("Error!\n");
goto scan;
}
Create(length);
}
else
length=maxnum;
Display(length,0);
DNF(length);
Display(length,1);
return 1;
}
void Create(int len)
{
int i=0;
char *in;
for(;i<len;i++)
{
input:
printf("Please enter the %dth color:",i+1);
scanf("%s",in);
if(strlen(in)>1||(*in!='0'&&*in!='1'&&*in!='2'))
{
printf("Error!\n");
goto input;
}
else
a[i]=*in-'0';
}
}
void Display(int len,int start)
{
int color=0,i=0;
if(start==0)
{
window(1,1,25,40);
textbackground(0);
clrscr();
printf("\nThe flag array you input is:\n");
}
else
if(start==1)
{
printf("\n\n\n");
printf("\nThe flag array calculated is:\n");
}
for(i=0; i<len; i++)
{
if(a[i]==red)
color=4;
else
if(a[i]==white)
color=7;
else
if(a[i]==blue)
color=1;
window(i*2+1,5+start*10,i*2+3,7+start*10);
textbackground(color);
clrscr();
}
}
void DNF(int len)
{
int r=0,w=0,b=len-1,temp;
while(w<=b)
{
if(a[w]==red)
{
temp=a[w];
a[w]=a[r];
a[r]=temp;
r++;
w++;
}
else
if(a[w]==white)
w++;
else
if(a[w]==blue)
{
temp=a[w];
a[w]=a[b];
a[b]=temp;
b--;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -