導航:首頁 > 文件教程 > 3liang設計網站源碼

3liang設計網站源碼

發布時間:2025-07-16 12:34:23

1. c語言糧油進銷存系統代碼

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>

//日期結構體
typedef struct
{
int year;
int month;
int day;
}DATE;
//商品結構體
//定義鏈表
typedef struct Node
{
long num;
char name[20];
char kind[20];
DATE pro_date;
int save_day;
int shuliang;
float jinjia;
float shoujia;
DATE sale_date;
struct Node *next;
}Node,*LinkList;
//申請函數
void apply()
{
int i,flag=1;
FILE *fp;
char name[20],key[20];
flushall();
printf("用戶名(不能為空):");
scanf("%s",name);
flushall();
printf("密碼(不能為空):");
for(i=0;i<=20;i++)
{
key[i]=getch();
if(key[i]==13)
{
key[i]='\0';
break;
}
printf("*");
}
fp=fopen("key.txt","w");
if(fp==NULL)
{
printf("the file can not open!");
flag=0;
exit(1);
}
fprintf(fp,"%s %s",name,key);
fclose(fp);
if(flag==1)
printf("\n申請成功,請登錄!\n");
else
printf("\n申請失敗,請重新申請!\n");
}
//登錄函數
int load()
{
FILE *fp;
int i;
char name[20],key[20];
char name1[20],key1[20];
fp=fopen("key.txt","r");
fscanf(fp,"%s %s",name,key);
fclose(fp);
printf("用戶名(不能為空):");
scanf("%s",name1);
flushall();
printf("密碼(不能為空):");
for(i=0;i<=20;i++)
{
key1[i]=getch();
if(key1[i]==13)
{
key1[i]='\0';
break;
}
printf("*");
}
printf("\n");
if(strcmp(name1,name)==0&&strcmp(key1,key)==0)
{ printf("登陸成功!\n\n");return 1; }
else
{ printf("用戶名或密碼錯誤;請重新登錄!"); return 0;}

}
//密碼保護系統
void key()
{
int choice,c;
do
{ printf("\n****************************申請登錄系統********************************\n\n");
printf(" 1: 新用戶注冊; \n\n");
printf(" 2: 新用戶登錄; \n\n");
printf("請選擇:");
scanf("%d",&choice);
switch(choice)
{
case 1: apply(); break;
case 2: c=load();break;
}
}while(c!=1);
}
LinkList goods_input()
{

LinkList L;
Node *p1,*p2;
int i=1;
void file_write(Node *p);
int flag=1;
L=p2=(Node*)malloc(sizeof(Node));//為頭節點分配存儲空間
while(flag)
{
p1=(Node*)malloc(sizeof(Node));
printf("請輸入第%d種商品的信息(商品號為0時,結束商品輸入):\n\n",i++);
flushall();
printf("商品號:");
scanf("%ld",&p1->num);
if(p1->num!=0)
{
flushall();
printf("名稱:");
scanf("%s",&p1->name);
flushall();
printf("類別:");
scanf("%s",&p1->kind);
flushall();
printf("生產日期(年月日用空格隔開):");
scanf("%d%d%d",&p1->pro_date.year,&p1->pro_date.month,&p1->pro_date.day);
flushall();
printf("保質期:");
scanf("%d",&p1->save_day);
flushall();
printf("商品數量:");
scanf("%d",&p1->shuliang);
flushall();
printf("進價:");
scanf("%f",&p1->jinjia);
flushall();
printf("售價:");
scanf("%f",&p1->shoujia);
flushall();
printf("銷售日期(年月日用空格隔開):");
scanf("%d%d%d",&p1->sale_date.year,&p1->sale_date.month,&p1->sale_date.day);
p2->next=p1;
p2=p1;
}
else
{
flag=0;
break;
}
}
p2->next=NULL;
file_write(L);
free(p1);
return(L);
}
//將商品信息寫入文件
void file_write(Node *p)
{

FILE *fp;
char filename[50];int c;
printf("是否保存?(保存按1;不保存按0):");
scanf("%d",&c);
if(c==1)
{ flushall();
printf("\n為了將你操作的信息保存下來,請輸入要寫入的文件的路經或文件:");
gets(filename);
fp=fopen(filename,"w");
if(fp==NULL)
{
printf("\n this file can not be open!");
exit(1);
}
p=p->next;
while(p!=NULL)
{
fprintf(fp,"%ld %s %s %d %d %d %d %d %f %f %d %d %d\n",p->num,p->name,p->kind,p->pro_date.year,p->pro_date.month,p->pro_date.day,p->save_day,p->shuliang,p->jinjia,p->shoujia,p->sale_date.year,p->sale_date.month,p->sale_date.day);
p=p->next;
}
fclose(fp);
printf("文件保存成功!");
}

}
//將文件中的信息讀出的函數
LinkList file_read()
{
FILE *fp;
LinkList L;
Node *p1,*p2;
char filename[50];
int i,k=0,t=-2;
flushall();
printf("請輸入要讀取的文件的路徑或文件名:");
gets(filename);
flushall();
printf("請輸入商品的種類數:");
scanf("%d",&i);
fp=fopen(filename,"r");
L=p2=(Node*)malloc(sizeof(Node));//為頭節點分配存儲空間
while(t!=EOF&&k<i)
{
p1=(Node*)malloc(sizeof(Node));
t=fscanf(fp,"%ld %s %s %d %d %d %d %d %f %f %d %d %d",&p1->num,p1->name,p1->kind,&p1->pro_date.year,&p1->pro_date.month,&p1->pro_date.day,&p1->save_day,&p1->shuliang,&p1->jinjia,&p1->shoujia,&p1->sale_date.year,&p1->sale_date.month,&p1->sale_date.day);
p2->next=p1;
p2=p1;
k++;
}
p2->next=NULL;
fclose(fp);
return L;
}
//查找商品信息
void goods_find()
{
long snum;
int flag=0,t;
Node *p0,*p1;
p1=p0=file_read();
while(1)
{
flag=0;
printf("請輸入你要查找的商品信息的商品號:");
scanf("%ld",&snum);
while( p0->next!=NULL)
{
p0=p0->next;
if(p0->num==snum)
{
flag=1;
break;
}
}
if(flag==1)
{ printf("該商品的信息如下:\n\n");
printf("商品號\t名稱\t類別\t生產日期\t保質期\t數量\t進價\t售價\t銷售日期\n");
printf("%ld\t%s\t%s\t%02d-%02d-%02d\t%d\t%d\t%0.2f\t%0.2f\t%02d-%02d-%02d",p0->num,p0->name,p0->kind,p0->pro_date.year,p0->pro_date.month,p0->pro_date.day,p0->save_day,p0->shuliang,p0->jinjia,p0->shoujia,p0->sale_date.year,p0->sale_date.month,p0->sale_date.day);
}
else
printf("此商品號不存在,查找失敗!\n");
p0=p1;
printf("結束查找按0,繼續查找按1:");
scanf("%d",&t);
if(t==0)
break;
}
}
//修改商品信息
void goods_change()
{
Node *p1,*p0,*p2;
int c,flag=0,t;
long snum;
p2=p0=file_read();
while(1)
{
flag=0;
p1=p0->next;
if(p1==NULL) flag=0;
printf("請輸入你要修改的商品信息的商品號:");
scanf("%ld",&snum);
while(p1!=NULL)
{
if(p1->num==snum)
{
flag=1;
break;
}
p1=p1->next;
}
if(flag==1)
{ printf(" 1:商品號;\n");
printf(" 2:商品名稱;\n");
printf(" 3:商品類別;\n");
printf(" 4:商品生產日期;\n");
printf(" 5:商品保質期;\n");
printf(" 6:商品數量\n");
printf(" 7:商品進價\n");
printf(" 8:商品售價\n");
printf(" 9:商品銷售日期\n");
printf(" 請選擇修改的內容(0~9):");
scanf("%d",&c);
while(1)
{
if(c==1||c==2||c==3||c==4||c==5||c==6||c==7||c==8||c==9)break;
else
{
printf("\n輸入有誤,請重新輸入!\n清選擇(0~9):");
scanf("%d",&c);
if(c==1||c==2||c==3||c==4||c==5||c==6||c==7||c==8||c==9) break;
}
}
switch(c)
{
case 1:
{
printf("\n輸入修改後的商品號:");
scanf("%ld",&p1->num);break;
}
case 2:
{
printf("輸入修改後的商品名:");
scanf("%s",&p1->name);break;
}
case 3:
{
printf("輸入修改後的商品類別:");
scanf("%s",&p1->kind);break;
}
case 4:
{
printf("輸入修改後的商品生產日期(年月日之間用空格隔開):");
scanf("%d%d%d",&p1->pro_date.year,&p1->pro_date.month,&p1->pro_date.day);break;
}
case 5:
{
printf("輸入修改後的商品保質期:");
scanf("%d",&p1->save_day);break;
}
case 6:
{
printf("輸入修改後的商品數量:");
scanf("%d",&p1->shuliang);break;
}
case 7:
{
printf("輸入修改後的商品進價:");
scanf("%f",&p1->jinjia);break;
}
case 8:
{
printf("輸入修改後的商品售價:");
scanf("%f",&p1->shoujia);break;
}
case 9:
{
printf("輸入修改後的商品銷售日期(年月日之間用空格隔開):");
scanf("%d%d%d",&p1->sale_date.year,&p1->sale_date.month,&p1->sale_date.day);break;
}
}
printf("修改後的商品信息如下:\n\n");
printf("商品號\t名稱\t類別\t生產日期\t保質期\t數量\t進價\t售價\t銷售日期\n");
printf("%ld\t%s\t%s\t%02d-%02d-%02d\t%d\t%d\t%0.2f\t%0.2f\t%02d-%02d-%02d",p1->num,p1->name,p1->kind,p1->pro_date.year,p1->pro_date.month,p1->pro_date.day,p1->save_day,p1->shuliang,p1->jinjia,p1->shoujia,p1->sale_date.year,p1->sale_date.month,p1->sale_date.day);
}
else
printf("此商品號不存在,修改失敗!\n");
p0=p2;
printf("結束修改按0,繼續修改按1:");
scanf("%d",&t);
if(t==0)
break;
}
file_write(p0);
}
//插入商品
void goods_insert()
{
Node *p0,*p1,*p2,*p3;
int k,i,flag,t;
p0=file_read();
while(1)
{
p3=p2=p0;
k=0;
printf("請輸入插入位置i的值(i的值小於商品的種類數):");
scanf("%d",&i);
while(p2!=NULL&&k<i-1)
{
p2=p2->next;
k=k+1;
}
if(k!=i-1) flag=0;
p1=(Node*)malloc(sizeof(Node));
printf("請輸入要插入的商品號 名稱 類別 生產日期 保質期 數量 進價 售價 銷售日期:\n");
scanf("%ld%s%s%d%d%d%d%d%f%f%d%d%d",&p1->num,p1->name,p1->kind,&p1->pro_date.year,&p1->pro_date.month,&p1->pro_date.day,&p1->save_day,&p1->shuliang,&p1->jinjia,&p1->shoujia,&p1->sale_date.year,&p1->sale_date.month,&p1->sale_date.day);
p1->next=p2->next;
p2->next=p1;
flag=1;
if(flag==1)
printf("插入位置合理!\n");
else
printf("插入位置不合理!\n");
printf("結束插入按0,繼續插入按1:");
scanf("%d",&t);
if(t==0)
break;
}
p0=p0->next;
printf("商品號\t名稱\t類別\t生產日期\t保質期\t數量\t進價\t售價\t銷售日期\n");
while(p0!=NULL)
{
printf("--------------------------------------------------------------------------------\n");
printf("%ld\t%s\t%s\t%02d-%02d-%02d\t%d\t%d\t%0.2f\t%0.2f\t%02d-%02d-%02d",p0->num,p0->name,p0->kind,p0->pro_date.year,p0->pro_date.month,p0->pro_date.day,p0->save_day,p0->shuliang,p0->jinjia,p0->shoujia,p0->sale_date.year,p0->sale_date.month,p0->sale_date.day);
p0=p0->next;
}
file_write(p3);
}
//刪除商品信息
void goods_delete()
{
long num;
Node *p,*p0,*p1,*p2;
int flag=0,t;
p0=file_read();
while(1)
{
flag=0;
p1=p2=p0;
p=p1->next;
if(p==NULL) flag=0;
printf("請輸入你要刪除的商品的商品號:");
scanf("%ld",&num);
while(p!=NULL)
{
if(p->num==num)
{
p1->next=p->next;
free(p);
flag=1;
break;
}
p1=p;
p=p->next;
flag=0;
}
if(flag==1)
printf("你已正確刪除!\n");
else
printf("你輸入的商品號不存在!\n");
printf("結束刪除按0,繼續刪除按1:");
scanf("%d",&t);
if(t==0)
break;
}
p0=p0->next;
printf("商品號\t名稱\t類別\t生產日期\t保質期\t數量\t進價\t售價\t銷售日期\n");
while(p0!=NULL)
{
printf("--------------------------------------------------------------------------------\n");
printf("%ld\t%s\t%s\t%02d-%02d-%02d\t%d\t%d\t%0.2f\t%0.2f\t%02d-%02d-%02d",p0->num,p0->name,p0->kind,p0->pro_date.year,p0->pro_date.month,p0->pro_date.day,p0->save_day,p0->shuliang,p0->jinjia,p0->shoujia,p0->sale_date.year,p0->sale_date.month,p0->sale_date.day);
p0=p0->next;
}

file_write(p2);
}
//商品信息排序
void goods_rank()
{
Node *p,*q,*k,*L,t;
Node *p0;
int flag=0;
L=file_read();
p=L->next;
while(p->next)
{
k=p;
q=p->next;
while(q)
{
if((k->shuliang)>(q->shuliang))
k=q;
q=q->next;
}
if(p!=k)
{
t=*p;
*p=*k;
*k=t;
t.next=p->next;
p->next=k->next;
k->next=t.next;
flag=1;
}
p=p->next;
}
if(flag=1)
printf("按商品數量從小到大排序成功!\n");
else
printf("按商品數量從小到大排序失敗!\n");
p0=L;
p0=p0->next;
printf("商品號\t名稱\t類別\t生產日期\t保質期\t數量\t進價\t售價\t銷售日期\n");
while(p0!=NULL)
{
printf("--------------------------------------------------------------------------------\n");
printf("%ld\t%s\t%s\t%02d-%02d-%02d\t%d\t%d\t%0.2f\t%0.2f\t%02d-%02d-%02d",p0->num,p0->name,p0->kind,p0->pro_date.year,p0->pro_date.month,p0->pro_date.day,p0->save_day,p0->shuliang,p0->jinjia,p0->shoujia,p0->sale_date.year,p0->sale_date.month,p0->sale_date.day);
p0=p0->next;
}

file_write(L);
}
//商品信息統計
void goods_tongji()
{
Node *p0,*p1;
int liang_sum=0;
float lirun_sum=0;
p0=p1=file_read();
p0=p0->next;
printf(" 商品信息統計表 \n\n");
printf("商品號\t名稱\t類別\t生產日期\t保質期\t數量\t進價\t售價\t銷售日期\n");
while(p0!=NULL)
{
printf("--------------------------------------------------------------------------------\n");
printf("%ld\t%s\t%s\t%02d-%02d-%02d\t%d\t%d\t%0.2f\t%0.2f\t%02d-%02d-%02d",p0->num,p0->name,p0->kind,p0->pro_date.year,p0->pro_date.month,p0->pro_date.day,p0->save_day,p0->shuliang,p0->jinjia,p0->shoujia,p0->sale_date.year,p0->sale_date.month,p0->sale_date.day);
p0=p0->next;
}
printf("\n");
p1=p1->next;
while(p1!=NULL)
{
liang_sum+=p1->shuliang;
// printf("商品數量:%d\n",p1->shuliang);
lirun_sum+=((p1->shoujia)-(p1->jinjia))*(p1->shuliang);
p1=p1->next;
}
printf("迄今,商店裡還有%d件商品;\n總利潤為%0.2f元;\n",liang_sum,lirun_sum);
if(liang_sum<=200)
printf("注意:商店裡的商品偏少,請適當進貨!\n");
else if(liang_sum>1100)
printf("注意:商店裡積壓的貨物太多,請及時清倉!\n");
else
printf("\n商品總件數大於200件,小於1100件,無需進貨,清倉!\n");
}
main()
{
int c;
key();
do
{
printf("請按任意鍵返回主菜單!");
getch();
system("cls");
printf("\n****************************歡迎進入商場店面管理系統****************************\n\n");
printf(" 1,錄入商品信息;\n");
printf(" 2,查找商品信息;\n");
printf(" 3,修改商品信息;\n");
printf(" 4,插入商品信息;\n");
printf(" 5,刪除商品信息;\n");
printf(" 6,商品信息排序;\n");
printf(" 7,統計商品信息;\n");
printf(" 0,退出系統;\n");
printf(" 請選擇(0~7):");
scanf("%d",&c);
while(1)
{
if(c==1||c==2||c==3||c==4||c==5||c==6||c==7||c==0)break;
else
{
printf("\n輸入有誤,請重新輸入!\n清選擇(0~7):");
scanf("%d",&c);
if(c==1||c==2||c==3||c==4||c==5||c==6||c==7||c==0) break;
}
}
switch(c)
{
case 1:goods_input();break;
case 2:goods_find();break;
case 3:goods_change();break;
case 4:goods_insert();break;
case 5:goods_delete();break;
case 6:goods_rank();break;
case 7:goods_tongji();break;
case 0 :break;
}
}while(c!=0);
}

2. 求C語言小程序源代碼,300行左右

黑白棋游戲
#include "graphics.h" /*圖形系統頭文件*/
#define LEFT 0x4b00 /*游標左鍵值*/
#define RIGHT 0x4d00 /*游標右鍵值*/
#define DOWN 0x5000 /*游標下鍵值*/
#define UP 0x4800 /*游標上鍵值*/
#define ESC 0x011b /* ESC鍵值*/
#define ENTER 0x1c0d /* 回車鍵值*/
int a[8][8]={0},key,score1,score2;/*具體分數以及按鍵與存放棋子的變數*/
char playone[3],playtwo[3];/*兩個人的得分轉換成字元串輸出*/
void playtoplay(void);/*人人對戰函數*/
void DrawQp(void);/*畫棋盤函數*/
void SetPlayColor(int x);/*設置棋子第一次的顏色*/
void MoveColor(int x,int y);/*恢復原來棋盤狀態*/
int QpChange(int x,int y,int z);/*判斷棋盤的變化*/
void DoScore(void);/*處理分數*/
void PrintScore(int n);/*輸出成績*/
void playWin(void);/*輸出勝利者信息*/
/******主函數*********/
void main(void)
{
int gd=DETECT,gr;
initgraph(&gd,&gr,"c:\\tc"); /*初始化圖形系統*/
DrawQp();/*畫棋盤*/
playtoplay();/*人人對戰*/
getch();
closegraph();/*關閉圖形系統*/
}
void DrawQp()/*畫棋盤*/
{
int i,j;
score1=score2=0;/*棋手一開始得分都為0*/
setbkcolor(BLUE);
for(i=100;i<=420;i+=40)
{
line(100,i,420,i);/*畫水平線*/
line(i,100,i,420); /*畫垂直線*/
}
setcolor(0);/*取消圓周圍的一圈東西*/
setfillstyle(SOLID_FILL,15);/*白色實體填充模式*/
fillellipse(500,200,15,15); /*在顯示得分的位置畫棋*/
setfillstyle(SOLID_FILL,8); /*黑色實體填充模式*/
fillellipse(500,300,15,15);
a[3][3]=a[4][4]=1;/*初始兩個黑棋*/
a[3][4]=a[4][3]=2;/*初始兩個白棋*/
setfillstyle(SOLID_FILL,WHITE);
fillellipse(120+3*40,120+3*40,15,15);
fillellipse(120+4*40,120+4*40,15,15);
setfillstyle(SOLID_FILL,8);
fillellipse(120+3*40,120+4*40,15,15);
fillellipse(120+4*40,120+3*40,15,15);
score1=score2=2; /*有棋後改變分數*/
DoScore();/*輸出開始分數*/
}
void playtoplay()/*人人對戰*/
{
int x,y,t=1,i,j,cc=0;
while(1)/*換棋手走棋*/
{
x=120,y=80;/*每次棋子一開始出來的坐標,x為行坐標,y為列坐標*/
while(1) /*具體一個棋手走棋的過程*/
{
PrintScore(1);/*輸出棋手1的成績*/
PrintScore(2);/*輸出棋手2的成績*/
SetPlayColor(t);/*t變數是用來判斷棋手所執棋子的顏色*/
fillellipse(x,y,15,15);
key=bioskey(0);/*接收按鍵*/
if(key==ESC)/*跳出遊戲*/
break;
else
if(key==ENTER)/*如果按鍵確定就可以跳出循環*/
{
if(y!=80&&a[(x-120)/40][(y-120)/40]!=1
&&a[(x-120)/40][(y-120)/40]!=2)/*如果落子位置沒有棋子*/
{
if(t%2==1)/*如果是棋手1移動*/
a[(x-120)/40][(y-120)/40]=1;
else/*否則棋手2移動*/
a[(x-120)/40][(y-120)/40]=2;
if(!QpChange(x,y,t))/*落子後判斷棋盤的變化*/
{
a[(x-120)/40][(y-120)/40]=0;/*恢復空格狀態*/
cc++;/*開始統計嘗試次數*/
if(cc>=64-score1-score2) /*如果嘗試超過空格數則停步*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
break;
}
else
continue;/*如果按鍵無效*/
}
DoScore();/*分數的改變*/
break;/*棋盤變化了,則輪對方走棋*/
}
else/*已經有棋子就繼續按鍵*/
continue;
}
else /*四個方向按鍵的判斷*/
if(key==LEFT&&x>120)/*左方向鍵*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
SetPlayColor(t);
x-=40;
fillellipse(x,y,15,15);
}
else
if(key==RIGHT&&x<400&&y>80)/*右方向鍵*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
SetPlayColor(t);
x+=40;
fillellipse(x,y,15,15);
}
else
if(key==UP&&y>120)/*上方向鍵*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
SetPlayColor(t);
y-=40;
fillellipse(x,y,15,15);
}
else
if(key==DOWN&&y<400)/*下方向鍵*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
SetPlayColor(t);
y+=40;
fillellipse(x,y,15,15);
}
}
if(key==ESC)/*結束游戲*/
break;
if((score1+score2)==64||score1==0||score2==0)/*格子已經占滿或一方棋子為0判斷勝負*/
{
playWin();/*輸出最後結果*/
break;
}
t=t%2+1; /*一方走後,改變棋子顏色即輪對方走*/
cc=0; /*計數值恢復為0*/
} /*endwhile*/
}
void SetPlayColor(int t)/*設置棋子顏色*/
{
if(t%2==1)
setfillstyle(SOLID_FILL,15);/*白色*/
else
setfillstyle(SOLID_FILL,8);/*灰色*/
}
void MoveColor(int x,int y)/*走了一步後恢復原來格子的狀態*/
{
if(y<100)/*如果是從起點出發就恢復藍色*/
setfillstyle(SOLID_FILL,BLUE);
else/*其他情況如果是1就恢復白色棋子,2恢復黑色棋子,或恢復藍色棋盤*/
switch(a[(x-120)/40][(y-120)/40])
{
case 1:
setfillstyle(SOLID_FILL,15);break; /*白色*/
case 2:
setfillstyle(SOLID_FILL,8);break; /*黑色*/
default:
setfillstyle(SOLID_FILL,BLUE); /*藍色*/
}
}
int QpChange(int x,int y,int t)/*判斷棋盤的變化*/
{
int i,j,k,kk,ii,jj,yes;
yes=0;
i=(x-120)/40; /*計算數組元素的行下標*/
j=(y-120)/40; /*計算數組元素的列下標*/
SetPlayColor(t);/*設置棋子變化的顏色*/
/*開始往8個方向判斷變化*/
if(j<6)/*往右邊*/
{
for(k=j+1;k<8;k++)
if(a[i][k]==a[i][j]||a[i][k]==0)/*遇到自己的棋子或空格結束*/
break;
if(a[i][k]!=0&&k<8)
{
for(kk=j+1;kk<k&&k<8;kk++)/*判斷右邊*/
{
a[i][kk]=a[i][j]; /*改變棋子顏色*/
fillellipse(120+i*40,120+kk*40,15,15);
}
if(kk!=j+1) /*條件成立則有棋子改變過顏色*/
yes=1;
}
}
if(j>1)/*判斷左邊*/
{
for(k=j-1;k>=0;k--)
if(a[i][k]==a[i][j]||!a[i][k])
break;
if(a[i][k]!=0&&k>=0)
{
for(kk=j-1;kk>k&&k>=0;kk--)
{
a[i][kk]=a[i][j];
fillellipse(120+i*40,120+kk*40,15,15);
}
if(kk!=j-1)
yes=1;
}
}
if(i<6)/*判斷下邊*/
{
for(k=i+1;k<8;k++)
if(a[k][j]==a[i][j]||!a[k][j])
break;
if(a[k][j]!=0&&k<8)
{
for(kk=i+1;kk<k&&k<8;kk++)
{
a[kk][j]=a[i][j];
fillellipse(120+kk*40,120+j*40,15,15);
}
if(kk!=i+1)
yes=1;
}
}
if(i>1)/*判斷上邊*/
{
for(k=i-1;k>=0;k--)
if(a[k][j]==a[i][j]||!a[k][j])
break;
if(a[k][j]!=0&&k>=0)
{
for(kk=i-1;kk>k&&k>=0;kk--)
{
a[kk][j]=a[i][j];
fillellipse(120+kk*40,120+j*40,15,15);
}
if(kk!=i-1)
yes=1;
}
}
if(i>1&&j<6)/*右上*/
{
for(k=i-1,kk=j+1;k>=0&&kk<8;k--,kk++)
if(a[k][kk]==a[i][j]||!a[k][kk])
break;
if(a[k][kk]&&k>=0&&kk<8)
{
for(ii=i-1,jj=j+1;ii>k&&k>=0;ii--,jj++)
{
a[ii][jj]=a[i][j];
fillellipse(120+ii*40,120+jj*40,15,15);
}
if(ii!=i-1)
yes=1;
}
}
if(i<6&&j>1)/*左下*/
{
for(k=i+1,kk=j-1;k<8&&kk>=0;k++,kk--)
if(a[k][kk]==a[i][j]||!a[k][kk])
break;
if(a[k][kk]!=0&&k<8&&kk>=0)
{
for(ii=i+1,jj=j-1;ii<k&&k<8;ii++,jj--)
{
a[ii][jj]=a[i][j];
fillellipse(120+ii*40,120+jj*40,15,15);
}
if(ii!=i+1)
yes=1;
}
}
if(i>1&&j>1)/*左上*/
{
for(k=i-1,kk=j-1;k>=0&&kk>=0;k--,kk--)
if(a[k][kk]==a[i][j]||!a[k][kk])
break;
if(a[k][kk]!=0&&k>=0&&kk>=0)
{
for(ii=i-1,jj=j-1;ii>k&&k>=0;ii--,jj--)
{
a[ii][jj]=a[i][j];
fillellipse(120+ii*40,120+jj*40,15,15);
}
if(ii!=i-1)
yes=1;
}
}
if(i<6&&j<6)/* 右下*/
{
for(k=i+1,kk=j+1;kk<8&&kk<8;k++,kk++)
if(a[k][kk]==a[i][j]||!a[k][kk])
break;
if(a[k][kk]!=0&&kk<8&&k<8)
{
for(ii=i+1,jj=j+1;ii<k&&k<8;ii++,jj++)
{
a[ii][jj]=a[i][j];
fillellipse(120+ii*40,120+jj*40,15,15);
}
if(ii!=i+1)
yes=1;
}
}
return yes;/*返回是否改變過棋子顏色的標記*/
}
void DoScore()/*處理分數*/
{
int i,j;
score1=score2=0;/*重新開始計分數*/
for(i=0;i<8;i++)
for(j=0;j<8;j++)
if(a[i][j]==1)/*分別統計兩個人的分數*/
score1++;
else
if(a[i][j]==2)
score2++;
}
void PrintScore(int playnum)/*輸出成績*/
{
if(playnum==1)/*清除以前的成績*/
{
setfillstyle(SOLID_FILL,BLUE);
bar(550,100,640,400);
}
setcolor(RED);
settextstyle(0,0,4);/*設置文本輸出樣式*/
if(playnum==1)/*判斷輸出哪個棋手的分,在不同的位置輸出*/
{
sprintf(playone,"%d",score1);
outtextxy(550,200,playone);
}
else
{
sprintf(playtwo,"%d",score2);
outtextxy(550,300,playtwo);
}
setcolor(0);
}
void playWin()/*輸出最後的勝利者結果*/
{
settextstyle(0,0,4);
setcolor(12);
if(score2>score1)/*開始判斷最後的結果*/
outtextxy(100,50,"black win!");
else
if(score2<score1)
outtextxy(100,50,"white win!");
else
outtextxy(60,50,"you all win!");
}

五子棋游戲
/*五子棋*/
#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
#include<bios.h>
#include<conio.h>

#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
#define SPACE 0x3920

#define BILI 20
#define JZ 4
#define JS 3
#define N 19

int box[N][N];
int step_x,step_y ;
int key ;
int flag=1 ;

void draw_box();
void draw_cicle(int x,int y,int color);
void change();
void judgewho(int x,int y);
void judgekey();
int judgeresult(int x,int y);
void attentoin();

void attention()
{
char ch ;
window(1,1,80,25);
textbackground(LIGHTBLUE);
textcolor(YELLOW);
clrscr();
gotoxy(15,2);
printf("游戲操作規則:");
gotoxy(15,4);
printf("Play Rules:");
gotoxy(15,6);
printf("1、按左右上下方向鍵移動棋子");
gotoxy(15,8);
printf("1. Press Left,Right,Up,Down Key to move Piece");
gotoxy(15,10);
printf("2、按空格確定落棋子");
gotoxy(15,12);
printf("2. Press Space to place the Piece");
gotoxy(15,14);
printf("3、禁止在棋盤外按空格");
gotoxy(15,16);
printf("3. DO NOT press Space outside of the chessboard");
gotoxy(15,18);
printf("你是否接受上述的游戲規則(Y/N)");
gotoxy(15,20);
printf("Do you accept the above Playing Rules? [Y/N]:");
while(1)
{
gotoxy(60,20);
ch=getche();
if(ch=='Y'||ch=='y')
break ;
else if(ch=='N'||ch=='n')
{
window(1,1,80,25);
textbackground(BLACK);
textcolor(LIGHTGRAY);
clrscr();
exit(0);
}
gotoxy(51,12);
printf(" ");
}
}
void draw_box()
{
int x1,x2,y1,y2 ;
setbkcolor(LIGHTBLUE);
setcolor(YELLOW);
gotoxy(7,2);
printf("Left, Right, Up, Down KEY to move, Space to put, ESC-quit.");
for(x1=1,y1=1,y2=18;x1<=18;x1++)
line((x1+JZ)*BILI,(y1+JS)*BILI,(x1+JZ)*BILI,(y2+JS)*BILI);
for(x1=1,y1=1,x2=18;y1<=18;y1++)
line((x1+JZ)*BILI,(y1+JS)*BILI,(x2+JZ)*BILI,(y1+JS)*BILI);
for(x1=1;x1<=18;x1++)
for(y1=1;y1<=18;y1++)
box[x1][y1]=0 ;
}

void draw_circle(int x,int y,int color)
{
setcolor(color);
setlinestyle(SOLID_LINE,0,1);
x=(x+JZ)*BILI ;
y=(y+JS)*BILI ;
circle(x,y,8);
}

void judgekey()
{
int i ;
int j ;
switch(key)
{
case LEFT :

if(step_x-1<0)
break ;
else
{
for(i=step_x-1,j=step_y;i>=1;i--)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(i<1)break ;
step_x=i ;
judgewho(step_x,step_y);
break ;
}
case RIGHT :

if(step_x+1>18)
break ;
else
{
for(i=step_x+1,j=step_y;i<=18;i++)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(i>18)break ;
step_x=i ;
judgewho(step_x,step_y);
break ;
}
case DOWN :

if((step_y+1)>18)
break ;
else
{
for(i=step_x,j=step_y+1;j<=18;j++)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(j>18)break ;
step_y=j ;
judgewho(step_x,step_y);
break ;
}
case UP :

if((step_y-1)<0)
break ;
else
{
for(i=step_x,j=step_y-1;j>=1;j--)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(j<1)break ;
step_y=j ;
judgewho(step_x,step_y);
break ;
}
case ESC :
break ;

case SPACE :
if(step_x>=1&&step_x<=18&&step_y>=1&&step_y<=18)
{
if(box[step_x][step_y]==0)
{
box[step_x][step_y]=flag ;
if(judgeresult(step_x,step_y)==1)
{
sound(1000);
delay(1000);
nosound();
gotoxy(30,4);
if(flag==1)
{
setbkcolor(BLUE);
cleardevice();
setviewport(100,100,540,380,1);
/*定義一個圖形窗口*/
setfillstyle(1,2);
/*綠色以實填充*/
setcolor(YELLOW);
rectangle(0,0,439,279);
floodfill(50,50,14);
setcolor(12);
settextstyle(1,0,5);
/*三重筆劃字體, 水平放?5倍*/
outtextxy(20,20,"The White Win !");
setcolor(15);
settextstyle(3,0,5);
/*無襯筆劃字體, 水平放大5倍*/
outtextxy(120,120,"The White Win !");
setcolor(14);
settextstyle(2,0,8);
getch();
closegraph();
exit(0);
}
if(flag==2)
{
setbkcolor(BLUE);
cleardevice();
setviewport(100,100,540,380,1);
/*定義一個圖形窗口*/
setfillstyle(1,2);
/*綠色以實填充*/
setcolor(YELLOW);
rectangle(0,0,439,279);
floodfill(50,50,14);
setcolor(12);
settextstyle(1,0,8);
/*三重筆劃字體, 水平放大8倍*/
outtextxy(20,20,"The Red Win !");
setcolor(15);
settextstyle(3,0,5);
/*無襯筆劃字體, 水平放大5倍*/
outtextxy(120,120,"The Red Win !");
setcolor(14);
settextstyle(2,0,8);
getch();
closegraph();
exit(0);
}
}
change();
break ;
}
}
else
break ;
}
}

void change()
{
if(flag==1)
flag=2 ;
else
flag=1 ;
}

void judgewho(int x,int y)
{
if(flag==1)
draw_circle(x,y,15);
if(flag==2)
draw_circle(x,y,4);
}

int judgeresult(int x,int y)
{
int j,k,n1,n2 ;
while(1)
{
n1=0 ;
n2=0 ;
/*水平向左數*/
for(j=x,k=y;j>=1;j--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*水平向右數*/
for(j=x,k=y;j<=18;j++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}

/*垂直向上數*/
n1=0 ;
n2=0 ;
for(j=x,k=y;k>=1;k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*垂直向下數*/
for(j=x,k=y;k<=18;k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}

/*向左上方數*/
n1=0 ;
n2=0 ;
for(j=x,k=y;j>=1,k>=1;j--,k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*向右下方數*/
for(j=x,k=y;j<=18,k<=18;j++,k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}

/*向右上方數*/
n1=0 ;
n2=0 ;
for(j=x,k=y;j<=18,k>=1;j++,k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*向左下方數*/
for(j=x,k=y;j>=1,k<=18;j--,k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}
return(0);
break ;
}
}

void main()
{
int gdriver=VGA,gmode=VGAHI;
clrscr();
attention();
initgraph(&gdriver,&gmode,"c:\\tc");
/* setwritemode(XOR_PUT);*/
flag=1 ;
draw_box();
do
{
step_x=0 ;
step_y=0 ;
/*draw_circle(step_x,step_y,8); */
judgewho(step_x-1,step_y-1);
do
{
while(bioskey(1)==0);
key=bioskey(0);
judgekey();
}
while(key!=SPACE&&key!=ESC);
}
while(key!=ESC);
closegraph();
}

3. 如何建立屬於自己的個人博客

一、對網站域名和空間的選擇

域名:一般會選擇比較正規點的域名商購買,比如:萬網、西部數碼...(一年也才幾十塊錢)。考慮到我們的域名是要續費的,如果說你買的域是那種不正規的域名商,哪天域名商倒閉了,那麼我的域名就不能使用了。還有一點值得注意的是:域名的選擇最好「見名知意」越短越好。一般會用自己的名字來命名。比如:段亮個人博客:www.anliang920.com

空間:分為國內空間和國外空間。

1、國內空間:需要備案網站才能上線,但是速度比國外空間要快一點,並且也穩定。

2、國外空間:指(除大陸外的空間)則不需要備案,可以直接使用。

一般我們對空間的選擇有兩點:第一、穩定性,第二、性價比。在這里我推薦大家可以去淘寶等商城上去買,至於空間穩不穩定這個我不知道,看自己的運氣吧!

空間大小個人建議:前期練手150M就夠了,後期根據自己個人需要來選擇空間大小。

二、選擇網站後台系統

我們不需要會PHP、JSP、ASP、.NET之類的動態語言來編寫網站後台,同樣也可以做出一個動態網站來。因為現在有很多開源免費的CMS系統(內容管理系統)可以簡單點理解成:一個可以為網站提供發布文章、圖片等等一些功能的工具

那麼常見的個人博客系統有哪些呢?博客後台系統的選擇,取決你空間伺服器是PHP的還是ASP的。

空間伺服器是PHP:那麼我推薦你使用wordPress系統,因為WordPress最容易上手的網站程序了,程序安裝5分鍾搞定,就算是新手,也可以在半小時內學會搭建WordPress博客。後台傻瓜式管理,主題,插件,都可以在可視化後台按鍵完成,就算你不懂任何一句代碼,也能輕松安裝使用。

空間伺服器是ASP:那麼我推薦你使用Z-Blog系統,程序小,運行速度快。據說著名草根站長「盧鬆鬆」的博客,也是用的這個系統。現在PHP版本也出來了,具體選擇看自己愛好。

當然並不只有這兩款博客後台系統才可以做網站後台,也可以用其它的CMS系統比如:帝國cms、織夢cms(本人就是用的織夢,來搭建的博客網站後台)..,甚至有能力可以自己開發網站後台。只是wordpress和Z-blog這兩款博客系統是非常有利於做博客,因為他們本身就是為博客而量身定做的。

三、策劃和設計網站效果圖

很多人可能會說:既然那些博客系統,都有現成的主題,那還需要自己親自DIY設計博客的效果圖嗎?那是因為網上的主題魚龍混雜的,畢竟每個人的審美觀不一樣,需求也不一樣!所以說:想做一個自己喜歡風格的網站,還是需要自己親自動手去設計。如果還沒想好怎麼去設計的朋友,我博客提供了一款比較簡潔的博客模板。

四、製作前台頁面

根據前面自己設計的效果圖,然後把它製作成html的靜態頁面模板。方便和後台的結合,實現真正意義的動態網站。

五、製作動態網站

可能有些新手就會問了,網站還分靜態網站和動態網站呀?為什麼要實現動態網站呢?因為動態網站可以實現靜態網站實現不了的功能,比如說:對網站文章的發布、圖片的更新、留言等功能。

六、測試以及上線

在本地搭建伺服器,網站上線前先測試網站有沒有什麼BUG。如沒有什麼問題,可以將本地網站解壓打包,使用FTP工具上傳到伺服器空間。

值得注意的是:先得把網站的資料庫導入出來,然後在空間伺服器還原。不然就會出錯誤喲!

如果沒有本地伺服器測試的朋友,我這里提供了一款本地服務測試工具。請點擊下載(放心使用,安全無毒!)

寫在最後:建立一個個人博客,其實跟建立網站流程是一樣的。只有你真正的了解這套開發流程,才知道網站是怎樣做出來的。

4. java冒泡排序法代碼

冒泡排序是比較經典的排序演算法。代碼如下:

for(int i=1;i<arr.length;i++){

for(int j=1;j<arr.length-i;j++){

//交換位置

}

拓展資料:

原理內:比較兩個相鄰的元素容,將值大的元素交換至右端。

思路:依次比較相鄰的兩個數,將小數放在前面,大數放在後面。即在第一趟:首先比較第1個和第2個數,將小數放前,大數放後。然後比較第2個數和第3個數,將小數放前,大數放後,如此繼續,直至比較最後兩個數,將小數放前,大數放後。重復第一趟步驟,直至全部排序完成。

第一趟比較完成後,最後一個數一定是數組中最大的一個數,所以第二趟比較的時候最後一個數不參與比較;

第二趟比較完成後,倒數第二個數也一定是數組中第二大的數,所以第三趟比較的時候最後兩個數不參與比較;

依次類推,每一趟比較次數-1;

……

舉例說明:要排序數組:int[]arr={6,3,8,2,9,1};

for(int i=1;i<arr.length;i++){

for(int j=1;j<arr.length-i;j++){

//交換位置

}

閱讀全文

與3liang設計網站源碼相關的資料

熱點內容
友盟分享微信一閃而過 瀏覽:821
數控編程和編程哪個好 瀏覽:745
如何清除網路已用流量 瀏覽:494
jsud83d 瀏覽:617
學習計算機編程app哪個好 瀏覽:401
ipad怎麼刪除視頻文件 瀏覽:564
建行友途車服app 瀏覽:353
湖南聯通的雙4g升級包 瀏覽:349
什麼app能刷考公的題 瀏覽:560
怎樣退出網路配置文件 瀏覽:506
提高日語口語的app 瀏覽:375
兩個表中相同數據如何切換 瀏覽:986
如何在ug編程里調出機床 瀏覽:639
金數據對外查詢系統怎麼使用 瀏覽:999
用word精確套印 瀏覽:704
宏病毒能感染exe類型的文件 瀏覽:564
兒童編程去哪裡學好 瀏覽:665
如何生成map文件 瀏覽:78
蘋果電腦復制文件 瀏覽:750
vegas字體教程 瀏覽:499

友情鏈接