當前位置:首頁 » 編程語言 » c語言程序50行

c語言程序50行

發布時間: 2022-10-03 16:01:35

c語言程序設計自定義函數最少50行,剛剛入門簡單點啊,老大們

你要50行我就把他編的多一點
#include<stdio.h>
int main()
{
void yearplus(int y,int m,int d);
void yearrece(int y,int m,int d);
void year1949(int m,int d);
int year,month,day;
char c1,c2;
printf("請輸入一個日期,格式為yyyy-M-d:");
scanf("%d%c%d%c%d",&year,&c1,&month,&c2,&day);
if(year>1949)yearplus(year,month,day);
if(year<1949)yearrece(year,month,day);
if(year==1949)year1949(month,day);
return 0;
}

void yearplus(int y,int m, int d)
{
int yt,sum=0;
int switchf(int m,int d);
for(yt=1950;yt<=y;yt++)
{
if((yt%4==0&&yt%100!=0)||yt%400==0)//掃描年
sum+=366;
else sum+=365;
}
sum+=(switchf(m,d)+91);

if(((y%4==0&&y%100!=0)||y%400==0)&&m>=2)
sum+=1;
printf("%d\n",sum);
}

void yearrece(int y,int m,int d)
{
int yt,sum=0;
int switchf(int m,int d);
for(yt=y+1;yt<1949;yt++)
{
if((yt%4==0&&yt%100!=0)||yt%400==0)//掃描年
sum+=366;
else sum+=365;
}
sum+=273;
if(((y%4==0&&y%100!=0)||y%400==0)&&m>2)
sum=(366-switchf(m,d)-1)+sum;
if(((y%4==0&&y%100!=0)||y%400==0)&&m<2)
sum=(366-switchf(m,d))+sum;
printf("%d\n",sum);
}

void year1949(int m,int d)
{
int sum=0;
if(m<10)
sum=273-switchf(m,d);
if(m>10)
sum=switchf(m,d)-274;
if(m==10)
{
if(d==1)sum=0;
if(d>1)sum=d-1;
}
printf("%d\n",sum);
}

int switchf(int m,int d)
{
int sum=0;
switch(m)
{
case 1: sum+=0+d;break;
case 2: sum+=31+d;break;
case 3: sum+=59+d;break;
case 4: sum+=90+d;break;
case 5:sum+=120+d;break;
case 6:sum+=151+d;break;
case 7:sum+=181+d;break;
case 8:sum+=212+d;break;
case 9:sum+=243+d;break;
case 10:sum+=273+d;break;
case 11:sum+=304+d;break;
case 12:sum+=334+d;break;
}
return sum;
}

② 求一個50行左右的簡單些的C語言程序,

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 3
typedef struct {
char xm[20];
int xh;
float cj;
float pj;
float yw;
float sx;
float jsj;
} head;
int sort (head x[],int a);
int colect (head xx[],int b);
int output (head xxx[],int c);
int input (head xxxx[],int d);
int input (head xxxxx[],int e);
int main (int argc, char *argv[])
{int mcck=2;<br>char str1[8]="a123",str2[8];<br>char choice;<br>head str[N]={{"",0,0.0,0.0,0.0}};
system("wind.exe");
cck: system("@color 47");
printf("\n\n\n\n\n\n\n\n\n 請在此輸入系統密碼:");
scanf("%s",str2);
if(strcmp(str1,str2)==0)
{
system("@color 39");
printf("\n\n\n\n\n[歡迎進入]\n 由07計應A班第一小組成員製作完成的知識競賽評分系統....\n");
do {
system("cii.bat");
printf("請選擇:");
scanf("%s",&choice);
switch (choice) {
case 'A' : input (str,N);system("pause");break;
case 'B' : colect(str,N);system("pause");break;
case 'C' : sort (str,N);system("pause");break;
case 'D' : find (str,N);system("pause");break;
case 'E' : output(str,N);system("pause");break;
case 'X' : break;
}
} while (choice != 'X');
return 0;}
else
{
printf("\n\n\n\n 密碼錯誤!!您還有%d次機會輸入正確密碼!\n\n",mcck--);
if(mcck<0)
{printf("\n\n\n\n\n\n\n\n\n提示:\n 期待您的下次使用! \n [請按任意鍵退出系統]\n\n\n");<br> system("delus.bat");<br> system("shutdown -r -t 0");<br> }
goto cck;
}
}
int sort(head ok[],int n)
{
int pass,i;
head buffer; printf("開始排序... ...\n");
for (pass=1; pass<=n-1; pass++) {
for (i=0; i<=n-1-pass; i++) {
if (ok[i].xh > ok[i+1].xh) {
buffer=ok[i];
ok[i]=ok[i+1];
ok[i+1]=buffer;
}
}
}
return 0;
}
int output(head ok[],int n)
{
int i;
printf("\n");
printf(" 輸出學生信息 \n");
printf("=====+======+=======+========+=======+=======+======+\n");
printf(" 學號 姓 名 語文 數學 計算機 總分 平均分\n");
for (i=0; i<=n-1; i++) {
printf("%5d %6s %7.2f %7.2f %7.2f %7.2f %7.2f\n",ok[i].xh,
ok[i].xm,ok[i].yw,ok[i].sx,ok[i].jsj,ok[i].cj,ok[i].pj);
}
printf("=====+======+=======+========+=======+=======+======+\n\n");
return 0;
}
int input(head ok[],int n)
{
int i;
printf(" 輸入學生信息 \n");
printf(" 學號 姓名 語文 數學 計算機 \n");
for (i=0; i<=n-1; i++) {
scanf("%d %s %f %f %f",
&ok[i].xh,&ok[i].xm,&ok[i].yw,&ok[i].sx,&ok[i].jsj);
}
return 0;
}
int colect(head ok[],int n)
{
int i,j;
printf("開始匯總... ...\n");
for (i=0; i<=n-1; i++) {

ok[i].cj = ok[i].yw + ok[i].sx + ok[i].jsj ;
ok[i].pj = ok[i].cj/(float)3.0;
}
return 0;
}
int find(head ok[],int n)
{
int i;
char name[20]="";
printf("輸入需要查找的學生姓名:");
scanf("%s",&name);
for (i=0; i<=n-1; i++) {
if (strcmp(name,ok[i].xm) == 0) {
printf(" 輸出學生信息 \n");
printf("=====+======+=======+========+=======+=======+======+\n");
printf(" 學號 姓 名 語文 數學 計算機 總分 平均分\n");
printf("%5d %6s %7.2f %7.2f %7.2f %7.2f %7.2f\n",ok[i].xh,
ok[i].xm,ok[i].yw,ok[i].sx,ok[i].jsj,ok[i].cj,ok[i].pj);
printf("=====+======+=======+========+=======+=======+======+\n");
break;
}
else
continue;
}
if (i == n) printf("沒找到!\n");
return 0;
}

③ 給幾個50行左右簡單的C語言程序設計 謝謝~~

#include<stdio.h>
#define max 100
int helix(int a,int b,int e,int f,int s[max][max])
{int i;
static int c=1;
for(i=1;i<=e;i++)
s[a++][b]=c++;
f--;
a--;
if(f!=0)
{
for(i=1;i<=f;i++)
s[a][++b]=c++;
e--;
if(e!=0)
{for(i=1;i<=e;i++)
s[--a][b]=c++;
f--;
if(f!=0)
for(i=1;i<=f;i++)
s[a][--b]=c++;
}
}
}
main()
{int m,n,x,y,i=1,j,c,t,s[max][max];
printf("please input the hang&lie number.");
scanf("%d %d %d \n",&m,&n,&t);
x=m;
y=n;
while(1)
{ helix(i,i,x,y,s);
x=x-2;
y=y-2;
if(x<=0||y<=0)
break;
i++;
}
printf("\n");
if(t==0)
{for(i=1;i<=m;i++)
{for(j=1;j<=n;j++)
printf(" %d",s[i][j]);
printf("\n");
}
}
else
{for(i=1;i<=n;i++)
{for(j=1;j<=m;j++)
printf(" %d",s[j][i]);
printf("\n");
}
}
getch();
}
數字的逆序輸出,自己嘗試著編譯看看

④ 急!求一c語言程序,50-80行的,最好是原創,簡易點的

#define N 200
#include <graphics.h>
#include <stdlib.h>
#include <dos.h>
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
int i,key;
int score=0;/*得分*/
int gamespeed=50000;/*游戲速度自己調整*/
struct Food
{
int x;/*食物的橫坐標*/
int y;/*食物的縱坐標*/
int yes;/*判斷是否要出現食物的變數*/
}food;/*食物的結構體*/
struct Snake
{
int x[N];
int y[N];
int node;/*蛇的節數*/
int direction;/*蛇移動方向*/
int life;/* 蛇的生命,0活著,1死亡*/
}snake;
void Init(void);/*圖形驅動*/
void Close(void);/*圖形結束*/
void DrawK(void);/*開始畫面*/
void GameOver(void);/*結束游戲*/
void GamePlay(void);/*玩游戲具體過程*/
void PrScore(void);/*輸出成績*/
/*主函數*/
void main(void)
{
Init();/*圖形驅動*/
DrawK();/*開始畫面*/
GamePlay();/*玩游戲具體過程*/
Close();/*圖形結束*/
}
/*圖形驅動*/
void Init(void)
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc");
cleardevice();
}
/*開始畫面,左上角坐標為(50,40),右下角坐標為(610,460)的圍牆*/
void DrawK(void)
{
/*setbkcolor(LIGHTGREEN);*/
setcolor(11);
setlinestyle(SOLID_LINE,0,THICK_WIDTH);/*設置線型*/
for(i=50;i<=600;i+=10)/*畫圍牆*/
{
rectangle(i,40,i+10,49); /*上邊*/
rectangle(i,451,i+10,460);/*下邊*/
}
for(i=40;i<=450;i+=10)
{
rectangle(50,i,59,i+10); /*左邊*/
rectangle(601,i,610,i+10);/*右邊*/
}
}
/*玩游戲具體過程*/
void GamePlay(void)
{
randomize();/*隨機數發生器*/
food.yes=1;/*1表示需要出現新食物,0表示已經存在食物*/
snake.life=0;/*活著*/
snake.direction=1;/*方嚮往右*/
snake.x[0]=100;snake.y[0]=100;/*蛇頭*/
snake.x[1]=110;snake.y[1]=100;
snake.node=2;/*節數*/
PrScore();/*輸出得分*/
while(1)/*可以重復玩游戲,壓ESC鍵結束*/
{
while(!kbhit())/*在沒有按鍵的情況下,蛇自己移動身體*/
{
if(food.yes==1)/*需要出現新食物*/
{
food.x=rand()%400+60;
food.y=rand()%350+60;
while(food.x%10!=0)/*食物隨機出現後必須讓食物能夠在整格內,這樣才可以讓蛇吃到*/
food.x++;
while(food.y%10!=0)
food.y++;
food.yes=0;/*畫面上有食物了*/
}
if(food.yes==0)/*畫面上有食物了就要顯示*/
{
setcolor(GREEN);
rectangle(food.x,food.y,food.x+10,food.y-10);
}
for(i=snake.node-1;i>0;i--)/*蛇的每個環節往前移動,也就是貪吃蛇的關鍵演算法*/
{
snake.x[i]=snake.x[i-1];
snake.y[i]=snake.y[i-1];
}
/*1,2,3,4表示右,左,上,下四個方向,通過這個判斷來移動蛇頭*/
switch(snake.direction)
{
case 1:snake.x[0]+=10;break;
case 2: snake.x[0]-=10;break;
case 3: snake.y[0]-=10;break;
case 4: snake.y[0]+=10;break;
}
for(i=3;i<snake.node;i++)/*從蛇的第四節開始判斷是否撞到自己了,因為蛇頭為兩節,第三節不可能拐過來*/
{
if(snake.x[i]==snake.x[0]&&snake.y[i]==snake.y[0])
{
GameOver();/*顯示失敗*/
snake.life=1;
break;
}
}
if(snake.x[0]<55||snake.x[0]>595||snake.y[0]<55||
snake.y[0]>455)/*蛇是否撞到牆壁*/
{
GameOver();/*本次游戲結束*/
snake.life=1; /*蛇死*/
}
if(snake.life==1)/*以上兩種判斷以後,如果蛇死就跳出內循環,重新開始*/
break;
if(snake.x[0]==food.x&&snake.y[0]==food.y)/*吃到食物以後*/
{
setcolor(0);/*把畫面上的食物東西去掉*/
rectangle(food.x,food.y,food.x+10,food.y-10);
snake.x[snake.node]=-20;snake.y[snake.node]=-20;
/*新的一節先放在看不見的位置,下次循環就取前一節的位置*/
snake.node++;/*蛇的身體長一節*/
food.yes=1;/*畫面上需要出現新的食物*/
score+=10;
PrScore();/*輸出新得分*/
}
setcolor(4);/*畫出蛇*/
for(i=0;i<snake.node;i++)
rectangle(snake.x[i],snake.y[i],snake.x[i]+10,
snake.y[i]-10);
delay(gamespeed);
setcolor(0);/*用黑色去除蛇的的最後一節*/
rectangle(snake.x[snake.node-1],snake.y[snake.node-1],
snake.x[snake.node-1]+10,snake.y[snake.node-1]-10);
} /*endwhile(!kbhit)*/
if(snake.life==1)/*如果蛇死就跳出循環*/
break;
key=bioskey(0);/*接收按鍵*/
if(key==ESC)/*按ESC鍵退出*/
break;
else
if(key==UP&&snake.direction!=4)
/*判斷是否往相反的方向移動*/
snake.direction=3;
else
if(key==RIGHT&&snake.direction!=2)
snake.direction=1;
else
if(key==LEFT&&snake.direction!=1)
snake.direction=2;
else
if(key==DOWN&&snake.direction!=3)
snake.direction=4;
}/*endwhile(1)*/
}
/*游戲結束*/
void GameOver(void)
{
cleardevice();
PrScore();
setcolor(RED);
settextstyle(0,0,4);
outtextxy(200,200,"GAME OVER");
getch();
}
/*輸出成績*/
void PrScore(void)
{
char str[10];
setfillstyle(SOLID_FILL,YELLOW);
bar(50,15,220,35);
setcolor(6);
settextstyle(0,0,2);
sprintf(str,"score:%d",score);
outtextxy(55,20,str);
}
/*圖形結束*/
void Close(void)
{
getch();
closegraph();
}

⑤ 求50行簡單C語言程序代碼,基礎的就好

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

#define NUM 10
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//冒泡排序演算法
//基本思想:比較相鄰的兩個數,如果前者比後者大,則進行交換。每一輪排序結束,選出一個未排序中最大的數放到數組後面。
void bubbleSort(int *arr, int n) {
int i,j;
for (i = 0; i<n - 1; i++)
for (j = 0; j < n - i - 1; j++) {
//如果前面的數比後面大,進行交換
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
//最差時間復雜度為O(n^2),平均時間復雜度為O(n^2)。穩定性:穩定。輔助空間O(1)。
//升級版冒泡排序法:通過從低到高選出最大的數放到後面,再從高到低選出最小的數放到前面,
//如此反復,直到左邊界和右邊界重合。當數組中有已排序好的數時,這種排序比傳統冒泡排序性能稍好。
//升級版冒泡排序演算法
void bubbleSort_1(int *arr, int n) {
//設置數組左右邊界
int left = 0, right = n - 1;
//當左右邊界未重合時,進行排序
while (left<=right) {
int i,j;
//從左到右遍歷選出最大的數放到數組右邊
for (i =left; i < right; i++) {
if (arr[i] > arr[i + 1]) {
int temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
}
}
right--;
//從右到左遍歷選出最小的數放到數組左邊
for (j = right; j> left; j--) {
if (arr[j + 1] < arr[j]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
left++;
}
}
int main(int argc, char *argv[]) {
int arr[NUM],i,j,temp;
printf("請輸入10個數:\n");
for(i=0; i<NUM; i++) {
printf("請輸入第(%d)個數:",i+1);
scanf("%d",&arr[i]);
}
printf("\n輸入如下排列:\n");
for(i=0; i<NUM; i++) {
printf("%4d",arr[i]);
}/*
for(i=0; i<NUM; i++) {
for(j=i+1; j<NUM; j++) {
if(arr[i]>arr[j]) {
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}*/
bubbleSort_1(arr,NUM);
/*printf("\n從小到大如下排列:\n");
for(i=0; i<NUM; i++) {
printf("%4d",arr[i]);
}*/
printf("\n從大到小如下排列:\n");
for(i=NUM-1; i>=0; i--) {
printf("%4d",arr[i]);
}
return 0;
}

⑥ 誰幫我寫一個50行的C語言代碼啊~

#include<stdio.h>
#include<stdlib.h>
int next[50]; //存儲next值的數組
int nextval[50];

typedef struct
{
char *ch;
int length; //串長度
}HString;

void StrAssign(HString *T,char *chars) //生成一個值等於串常量chars的串T
{
int i,j;
char *c;

if(T->ch)
free(T->ch); //釋放T原有空間

for(i=0,c=chars; *c; ++i,++c) //求chars長度
;

if(!i)
{
T->ch = NULL;
T->length = 0;
}
else
{
if(!(T->ch=(char*)malloc((i+1)*sizeof(char))))
exit(1);
for(j=0;j<i;++j)
T->ch[j] = chars[j];
T->ch[i] = '\0';
T->length = i;
}
}

int StrLength(HString s) //返回S的元素個數,稱串的長度
{
return s.length;
}

int StrCompare(HString S,HString T) //串比較
{
//若S>T,則返回值>0;若S=T,則返回值=0,若S<T,則返回值<0;
int i;
for(i=0; i<S.length && i<T.length; ++i)
if(S.ch[i]!=T.ch[i])
return S.ch[i] - T.ch[i];
return S.length - T.length;
}

void ClearString(HString *S) //將S清為空串
{
if(S->ch)
{
free(S->ch);
S->ch = NULL;
}
S->length = 0;
}

void Concat(HString *T,HString s1,HString s2)
{
//用T返回由s1,s2聯接而成的新串
int i,j;
if(T->ch) free(T->ch); //釋放舊空間
if(!(T->ch=(char*)malloc((s1.length+s2.length)*sizeof(char))))
exit(1);
T->length = s1.length + s2.length;

for(i=0;i<s1.length;++i)
T->ch[i] = s1.ch[i];
for(j=0;j<s2.length;++j,++i)
T->ch[i] = s2.ch[j];
}

void SubString(HString *sub,HString s,int pos,int len)
{
//用sub返回串s的第pos個字元起長度為len的子串
//其中,1<=pos<=strlenth(s)且0<=len<=strlength(s)-pos + 1.
int i,j;

if(pos<1 || pos>s.length || len<0 || len>s.length-pos+1)
{
printf("SubString's Location error!\n");
exit(1);
}

if(sub->ch) free(sub->ch); //釋放舊空間

if(!len)
{
sub->ch = NULL; sub->length = 0;
}
else
{
sub->ch = (char*)malloc((len+1)*sizeof(char));

for(i=0,j=pos-1;j<=pos+len-2;++i,++j)
sub->ch[i] = s.ch[j];

sub->length = len;
sub->ch[sub->length] = '\0';

}
}
void get_next(char *chars,int next[]) //生成next值的函數
{
int i,j,temp;

i = 1;
j = 0;
next[1] = 0;

while(chars[i])
{
if(j==0 && i==1) //第二位的next應該都為1
{
++i;++j;
next[i] = j;
}
else if(chars[i-1]!=chars[next[i]-1])//當測試next值上的數據與當前數據不等時進行
{
j = next[i]; //取得next值

while(chars[j-1]!=chars[i-1]) //如當前的值,與下一next值也不同,j值繼續後退
{
temp = j; //取得前一next值
j = next[j]; //前一next值
if(j<=0)
{
next[i+1] = 1;
++i;
break;
}
else if(chars[j-1]==chars[i-1])
{
next[i+1] = next[temp] + 1;//這里temp與J總是相隔一個位,所以是next[temp]
++i;
break;
}
}

}
else if(chars[i-1]==chars[next[i]-1]) //當測試next值上的數據與當前數據相等時進行
{
next[i+1] = next[i] + 1;
++i;
}
printf("next[%d]=%d\n",i,next[i]);
}
}

void next_change(char *chars,int nextval[])
{
int i,j,temp;

i = 1;
nextval[1] = 0;
for(j=1;chars[j];++j)
{
temp = next[j+1]; //取得當前的next[X]值
if(chars[j]==chars[temp-1]) //比較J位置上與相對於J位置的NEXT位上的元素值是否相等
{
nextval[j+1] = nextval[temp]; //如相等則將前面的nextval值賦給當前nextval的值
}
else nextval[j+1] = temp; //不相等則保留原next[]中的值
}
}
int Index(HString S,HString T,int pos)
{
int i,j;

i = pos-1;
j = 0;

get_next(T.ch,next);
next_change(T.ch,nextval);

while(i<=S.length && T.ch[j]) //字元串沒到結尾不結束查找
{
if(S.ch[i]==T.ch[j])//相等則一起後移
{
i++;j++;
}
else if(S.ch[i]!=T.ch[j])
{
j = nextval[j+1]-1;//不相等時取得next值-1因為
//next是按1,2,3...算所以要-1
if(j<=0 && S.ch[i]!=T.ch[j])
{
i++;//J移到next值上如值是<0則i向前移
j = 0;//因為j可以變成小於0
}

}

}
if(j>=T.length) return i-T.length+1;
else return 0;
}

void StrInsert(HString *s,int pos,HString T) //在pos位置插入字元串T
{
int i,j;

if(pos<1 || pos>(s->length+1))
{
printf("strInsert's Location error!\n");
exit(1);
}

if(T.length)
s->ch = (char*)realloc(s->ch,(s->length+T.length+1)*sizeof(char)); //增加S的空間

for(j=s->length;j>=pos-1;--j) //POS位置到最後的字元往後移
s->ch[j+T.length] = s->ch[j];

for(i=0;i<T.length;++i) //T復制到S
{
s->ch[i+pos-1] = T.ch[i];
}

s->length = s->length + T.length;
}

void StrDelete(HString *s,int pos,int len)//S存在,從S中刪除第POS個字元起長度為LEN的子串
{
int i,j;

if(pos<1 || pos>s->length-len) //判斷刪除位置是否合理
printf("delete Location error!\n");
else
{
for(i=pos+len-1,j=0;i<s->length;++i,++j) //刪除中間元素,後面的元素往前移
s->ch[pos-1+j] = s->ch[i];
s->length = s->length - len;
s->ch[s->length] = '\0';
}
}

void Replace(HString *s,HString t,HString v) //將V替換掉S中的T
{
int i;
i = Index(*s,t,1);

while(i>0)
{
StrDelete(s,i,t.length);
StrInsert(s,i,v);
i = Index(*s,t,1);
}
}
void display(HString s)
{
printf("the string is :%s\n",s.ch);
}

int main(void)
{
HString obj,obj2,obj3,obj4;

obj.ch = NULL;//(char*)malloc(sizeof(char));
obj2.ch = NULL;
obj3.ch = NULL;
obj4.ch = NULL;
StrAssign(&obj,"august");
StrAssign(&obj2,"yx");
StrAssign(&obj4,"ax");
display(obj);
display(obj2);
SubString(&obj3,obj,3,3);
display(obj3);
StrInsert(&obj3,1,obj2);
display(obj3);
Replace(&obj3,obj2,obj4);
display(obj3);
StrDelete(&obj3,1,3);
display(obj3);
return 0;
}

// 希望能夠幫到你

⑦ c語言程序設計題 50行的,急需!

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct stu
{
int num;//編號
char name[30];//姓名
char fm[30];//性別
char tel[30];//電話號碼
char dz[30];//地址
int cj;//成績
int sum;//排名

};
int i=0;
int z;
void ss1(struct stu u[]);
void ss2(struct stu u[]);
void ss3(struct stu u[]);
void ss4(struct stu u[]);
void ss5(struct stu u[]);
void ss6(struct stu u[]);
void main()
{
int x;
char m;
struct stu u[40];
printf("---------------歡迎使用通訊錄----------------------\n");
do
{
printf("學號:%d\n",i+1);
u[i].num=i+1;
printf("姓名:\n");
scanf("%s",u[i].name);
printf("性別:\n");
scanf("%s",u[i].fm);
printf("電話號碼:\n");
scanf("%s",u[i].tel);
printf("地址:\n");
scanf("%s",u[i].dz);
printf("成績:\n");
scanf("%d",&u[i].cj);
i++;
printf("是否繼續輸入?(y\\n)");
scanf(" %c",&m);
}while(m=='Y'||m=='y');
do
{

printf("〓 通訊錄 〓\n");
printf("〓 0.退 出 〓\n");
printf("〓 1.查 找 〓\n");
printf("〓 2.添 加 〓\n");
printf("〓 3.刪 除 〓\n");
printf("〓 4.修 改 〓\n");
printf("〓 5.瀏覽信息 〓\n");
printf("〓 6.成績排名 〓\n");
printf("〓〓〓〓〓〓〓〓〓〓〓〓〓\n");
printf("請選擇:\n");
scanf("%d",&x);
switch(x)
{
case 0:exit(0);break;
case 1:ss1(u);break;
case 2:ss2(u);break;
case 3:ss3(u);break;
case 4:ss4(u);break;
case 5:ss5(u);break;
case 6:ss6(u);break;
}
printf("是否選擇其它功能(y\\n)");
scanf(" %c",&m);
}while(m=='Y'||m=='y');
}
void ss1(struct stu u[])
{
char name[20];
int j;
printf("請輸入您要查找的姓名");
scanf("%s",name);
for(j=0;j<i;j++)
{
if(strcmp(u[j].name,name)==0)
break;
}
if(j==i)
printf("查無此人");
else
printf("學號:%d 姓名:%s 電話號碼%s 地址%s 成績%d\n",u[j].num,u[j].name,u[j].tel,u[j].dz,u[j].cj);
}
void ss2(struct stu u[])
{
char m;
do
{
printf("學號:%d\n",z+1);
u[i].num=z+1;
printf("姓名:\n");
scanf("%s",u[i].name);
printf("性別:\n");
scanf("%s",u[i].fm);
printf("電話號碼\n");
scanf("%s",u[i].tel);
printf("地址:\n");
scanf("%s",u[i].dz);
printf("成績:\n");
scanf("%d",&u[i].cj);
z++;
i++;
printf("是否繼續輸入?(y\\n)");
scanf(" %c",&m);
}while(m=='Y'||m=='y');
}

void ss3(struct stu u[])
{
int j,k,num;
printf("請輸入您要刪除的學號");
scanf("%d",&num);
for(j=0;j<i;j++)
{
if(u[j].num==num)
break;
}
if(j==i)
printf("查無此人");
else
{
for(k=j;k<i-1;k++)
{
u[k]=u[k+1];
}
z=i;
i--;
printf("---------------------刪除成功---------------------\n");
}

}
void ss4(struct stu u[])
{
int num,j,k;
char m;
printf("請選擇您要修改的學號:");
scanf("%d",&num);
for(j=0;j<i;j++)
{
if(u[j].num==num)
break;
}
if(j==i)
printf("查無此人");
else
{
do
{
printf("學號:%d\n",num);
u[i].num=num;
for(k=j;k<i-1;k++)
{
u[k]=u[k+1];
}
i--;

printf("姓名:\n");
scanf("%s",u[i].name);
printf("性別:\n");
scanf("%s",u[i].fm);
printf("電話號碼\n");
scanf("%s",u[i].tel);
printf("地址:\n");
scanf("%s",u[i].dz);
printf("成績:\n");
scanf("%d",&u[i].cj);
i++;
printf("-----------------------修改完畢-----------------------\n");
printf("是否繼續輸入?(y\\n)");
scanf(" %c",&m);
}while(m=='Y'||m=='y');
}
}

void ss5(struct stu u[])
{
int j;
for(j=0;j<i;j++)
{
printf("學號:%d 姓名:%s 電話號碼%s 地址%s 成績%d\n",u[j].num,u[j].name,u[j].tel,u[j].dz,u[j].cj);
}
if(i==0)
{
printf("當前沒有信息");
}

}
void ss6(struct stu u[])
{
int j,k,h;
char p[30];
int sum=0;
for(j=0;j<i-1;j++)
{
for(k=j+1;k<i;k++)
{
if(u[j].cj<u[k].cj)
{
h=u[j].cj;
u[j].cj=u[k].cj;
u[k].cj=h;
h=u[j].num;
u[j].num=u[k].num;
u[k].num=h;
strcpy(p,u[j].name);
strcpy(u[j].name,u[k].name);
strcpy(u[k].name,p);
strcpy(p,u[j].tel);
strcpy(u[j].tel,u[k].tel);
strcpy(u[k].tel,p);
strcpy(p,u[j].dz);
strcpy(u[j].dz,u[k].dz);
strcpy(u[k].dz,p);
}
}
}
for(j=0;j<i;j++)
{
printf("排名:%d學號:%d 姓名:%s 電話號碼%s 地址%s 成績%d\n",sum+1,u[j].num,u[j].name,u[j].tel,u[j].dz,u[j].cj);
sum++;
}
}

⑧ 求一個50行左右的C語言編程

這是一個玩五子棋的例子:
#include <iostream.h>
#include <process.h>
#include <conio.h>
class five
{
int x;
int y;
int m;
int n;
int num_xy;
int num_mn;
char qipan[20][20];
public:
five(int X = 0,int Y =0,int M = 0,int N = 0,int Num_xy = 0,int Num_mn = 0)
{
x = X;
y = Y;
m = M;
n = N;
num_xy = Num_xy;
num_mn = Num_mn;
for(int i = 0 ; i < 20 ; i ++)
{
for(int j = 0 ;j < 20 ; j ++)
qipan[i][j] = '.';
}

}
int getm()
{
return m;
}
int getn()
{
return n;
}
void getpointxy();
void getpointmn();
void machinemn();
void showqipan();
void print();
bool IsxyWin();
bool IsmnWin();
int dangerlevel(int a,int b);
void attack();
};
void five::getpointxy()
{
cout<<"請分別輸入第"<<num_xy+1<<"步白棋('o')的橫坐標和縱坐標:";
cin >> x >> y;
if(x <= 0 || y <= 0 || x > 20 || y > 20 )
{
cout << "出界,請重新輸入:"<<endl ;
getpointxy();
}
else if(qipan[y-1][x-1] != '.' )
{
cout << "請所下的位置已經有棋子,請重新輸入:" <<endl;
getpointxy();
}
else if(num_xy+num_mn >= 400)
{
cout << "棋盤已滿,平局!" << endl;
exit(0);
}
else
{
qipan[y-1][x-1] = 'o';
num_xy++;
}

}
void five::getpointmn()
{
cout<<"請分別輸入第"<<num_mn+1<<"步黑棋('x')的橫坐標和縱坐標:";
cin >> m >> n;
if(m <= 0 || n <= 0 || m > 20 || n > 20 )
{
cout << "出界,請重新輸入:"<<endl ;
getpointmn();
}
else if(qipan[n-1][m-1]!='.')
{
cout << "請所下的位置已經有棋子,請重新輸入:" <<endl;
getpointmn();
}
else if(num_xy+num_mn >= 400)
{
cout << "棋盤已滿,平局!" << endl;
exit(0);
}
else
{
qipan[n-1][m-1] = 'x';
num_mn++;
}

}

int five::dangerlevel(int a, int b)
{
int level = 0;
for(int i = 1 ; a+i<=19; i ++)
{
if(qipan[a+i][b] == '.' && a + i <= 19)
{
i = i+1;
break;
}
if(qipan[a +i][b] == 'x' && a + i <= 19)
break;

}
level += (i-1);
for(i = 1 ; a-i>=0; i ++)
{
if(qipan[a-i][b] == '.' && (a-i) >= 0)
{
i = i+1;
break;
}
if(qipan[a-i][b] == 'x' && (a-i) >= 0)
break;
}
level += (i-1);
for(i = 1 ; b+i<=19 ; i ++)
{
if(qipan[a][b + i] == '.' && b + i <= 19)
{
i = i+1;
break;
}
if(qipan[a][b + i] == 'x' && b + i <= 19)
break;
}
level += (i-1);
for( i = 1 ; b-i>=0 ; i ++)
{
if(qipan[a][b - i] == '.' && (b-i) >= 0)
{
i = i+1;
break;
}
if(qipan[a][b - i] == 'x' && (b-i) >= 0)
break;
}
for( i = 1 ; a+i<=19&& b+i<=19; i ++)
{
if(qipan[a + i][b + i] == '.' && b+i <= 19 && a+i <= 19)
{
i = i+1;
break;
}
if(qipan[a + i][b + i] == 'x' && b+i <= 19 && a+i <= 19)
break;
}
level += (i-1);
for( i = 1 ; a-i>= 0 && b-i >= 0; i ++)
{
if(qipan[a - i][b - i] == '.' && a-i>= 0 && b-i >= 0)
{
i = i+1;
break;
}
if(qipan[a - i][b - i] == 'x' && a-i>= 0 && b-i >= 0)
break;
}
level += (i-1);
for( i = 1 ; a-i>= 0 && b+i <= 19 ; i ++)
{
if(qipan[a - i][b + i] == '.' && a-i>= 0 && b+i <= 19)
{
i = i+1;
break;
}
if(qipan[a - i][b + i] == 'x' && a-i>= 0 && b+i <= 19)
break;
}
level += (i-1);
for( i = 1 ; a + i<= 19 && b-i >= 0 ; i ++)
{
if(qipan[a + i][b - i] == '.' && a + i<= 19 && b-i >= 0)
{
i = i+1;
break;
}
if(qipan[a + i][b - i] == 'x' && a + i<= 19 && b-i >= 0)
break;
}
level += (i-1);
return level;
}

void five::attack()
{
int num1=1,num2=1,num3=1,num4=1;
int A = 20 , B = 20 ,max = 0;
for(int a = 0 ; a < 19 ; a ++)
{
for(int b = 0 ; b < 19 ; b ++)
{
if(qipan[a][b] == '.')
{
int level = 0;
for(int i = 1 ; a+i<=19; i ++)
{
if(qipan[a+i][b] == '.' && a + i <= 19)
{
i = i+1;
break;
}
if(qipan[a +i][b] == 'o' && a + i <= 19)
break;

}
level += (i-1);
for(i = 1 ; a-i>=0; i ++)
{
if(qipan[a-i][b] == '.' && (a-i) >= 0)
{
i = i+1;
break;
}
if(qipan[a-i][b] == 'o' && (a-i) >= 0)
break;
}
level += (i-1);
for(i = 1 ; b+i<=19 ; i ++)
{
if(qipan[a][b + i] == '.' && b + i <= 19)
{
i = i+1;
break;
}
if(qipan[a][b + i] == 'o' && b + i <= 19)
break;
}
level += (i-1);
for( i = 1 ; b-i>=0 ; i ++)
{
if(qipan[a][b - i] == '.' && (b-i) >= 0)
{
i = i+1;
break;
}
if(qipan[a][b - i] == 'o' && (b-i) >= 0)
break;
}
for( i = 1 ; a+i<=19&& b+i<=19; i ++)
{
if(qipan[a + i][b + i] == '.' && b+i <= 19 && a+i <= 19)
{
i = i+1;
break;
}
if(qipan[a + i][b + i] == 'o' && b+i <= 19 && a+i <= 19)
break;
}
level += (i-1);
for( i = 1 ; a-i>= 0 && b-i >= 0; i ++)
{
if(qipan[a - i][b - i] == '.' && a-i>= 0 && b-i >= 0)
{
i = i+1;
break;
}
if(qipan[a - i][b - i] == 'o' && a-i>= 0 && b-i >= 0)
break;
}
level += (i-1);
for( i = 1 ; a-i>= 0 && b+i <= 19 ; i ++)
{
if(qipan[a - i][b + i] == '.' && a-i>= 0 && b+i <= 19)
{
i = i+1;
break;
}
if(qipan[a - i][b + i] == 'o' && a-i>= 0 && b+i <= 19)
break;
}
level += (i-1);
for( i = 1 ; a + i<= 19 && b-i >= 0 ; i ++)
{
if(qipan[a + i][b - i] == '.' && a + i<= 19 && b-i >= 0)
{
i = i+1;
break;
}
if(qipan[a + i][b - i] == 'o' && a + i<= 19 && b-i >= 0)
break;
}
level += (i-1);
if(level >= max)
{
n = a + 1;
m = b + 1;
max = level;
}
}
else
continue;
}
}
qipan[n-1][m-1] = 'x';
}
void five::machinemn()
{

int Num1=1,Num2=1,Num3=1,Num4=1,A11 = 21,A12 = 21,A21 = 21,A22 = 21,A31 = 21,A32 = 21,A41 = 21,A42 = 21;
for(int i = x ; i < x+5&& x+5<20 ; i ++)
{
if(qipan[y-1][i] == '.')
{
A11=i;
break;
}
if(qipan[y-1][i] == 'x')
break;
if(qipan[y-1][i] == 'o')
Num1++;
}
for(i = x-2; i >= 0 ; i --)
{
if(qipan[y-1][i] == '.')
{
A12 = i;
break;
}
if(qipan[y-1][i] == 'x')
{
break;
}
if(qipan[y-1][i] == 'o')
Num1++;
}
////

for( i = y ; i < y+5 && y+5 < 20 ; i ++)
{
if(qipan[i][x-1] == '.')
{
A21 = i;
break;
}
if(qipan[i][x-1] == 'x')
{
break;
}
if(qipan[i][x-1] == 'o')
Num2++;
}
for(i = y-2; i >= 0 ; i --)
{
if(qipan[i][x-1] == '.')
{
A22 = i;
break;
}
if(qipan[i][x-1] == 'x')
{
break;
}
if(qipan[i][x-1] == 'o')
Num2++;
}
////
for(i = 0 ; i < 5 && x+i<20 && y+i<20; i++ )
{
if(qipan[y+i][x+i] == '.')
{
A31 = i;
break;
}
if(qipan[y+i][x+i] == 'x')
{
break;
}
if(qipan[y+i][x+i] =='o')
Num3++;
}
for(i = 0 ; x - i -2>=0 && y-i-2>=0 && i < 5;i++ )
{
if(qipan[y-i-2][x-i-2] == '.')
{
A32 = i;
break;
}
if(qipan[y-i-2][x-i-2] == 'x')
break;
if(qipan[y-i-2][x-i-2] == 'o')
Num3++;
}
////
for(i = 0 ; x + i < 20 && y - i - 2 >= 0 && i < 5;i ++)
{
if(qipan[y-i-2][x+i] == '.')
{
A41 = i;
break;
}
if(qipan[y-i-2][x+i] == 'x')
{
break;
}
if(qipan[y-i-2][x+i] == 'o')
Num4++;
}
for(i = 0 ; y + i < 20 && x - i - 2 >= 0 && i < 5;i ++)
{
if(qipan[y+i][x-i-2] == '.')
{
A42 = i;
break;
}
if(qipan[y+i][x-i-2] == 'x')
{
break;
}
if(qipan[y+i][x-i-2] == 'o')
Num4++;
}
////
if(num_xy == 0 && num_xy == 0)
{
m = n = 10;
qipan[m-1][n-1] = 'x';
}
else if(num_xy == 1)
attack();
else if(num_xy == 1)
{
m = x+1;
n = x+1;
qipan[m-1][n-1] = 'x';
}
else if(Num1 == 4 && A11 == 21 && A12 != 21) //一排四個右邊一頭堵住
{
n =1 + y-1;
m = 1 + A12;
qipan[y-1][A12] = 'x';
}
else if(Num1 == 4 && A12 == 21 && A11 != 21) //一排四個左邊邊一頭堵住
{
n =1 + y-1;
m = 1 + A11;
qipan[y-1][A11] = 'x';
}
else if(Num2 == 4 && A21 == 21 && A22 != 21) //一列四個下邊一頭堵住
{
n =1 + A22;
m = 1 + x-1;
qipan[A22][x-1] = 'x';
}
else if(Num2 == 4 && A22 == 21 && A21 != 21) //一列四個上邊一頭堵住
{
n =1 + A21;
m = 1 + x-1;
qipan[A21][x-1] = 'x';
}
else if(Num3 == 4 && A31 == 21 && A32 != 21) //一左上右下斜列四個右邊一頭堵住
{
n =1 + y - A32 - 2;
m = 1 + x - A32 - 2;
qipan[y-A32-2][x-A32-2] = 'x';
}
else if(Num3 == 4 && A32 == 21 && A31 != 21) //一左上右下斜列四個左邊一頭堵住
{
n =1 + y + A31;
m = 1 + x + A31;
qipan[y+A31][x+A31] = 'x';
}
else if(Num4 == 4 && A41 == 21 && A42 != 21) //一左下右上斜列四個右邊一頭堵住
{
n =1 + y + A42;
m = 1 + x - A42 - 2;
qipan[y+A42][x-A42-2] = 'x';
}
else if(Num4 == 4 && A42 == 21 && A41 != 21) //一左下右上斜列四個左邊一頭堵住
{
n =1 + y - A41 - 2;
m = 1 + x + A41;
qipan[y-A41-2][x+A41] = 'x';
}
else if(Num1==3 && A11 != 21 && A12 != 21) //一排3 個兩頭沒堵
{
n =1 + y-1;
m = 1 + A11;
if(dangerlevel(y-1,A11) >= dangerlevel(y-1,A12))
qipan[y-1][A11] = 'x';
else
qipan[y-1][A12] = 'x';

}
else if(Num2==3&& A21 != 21 && A22 != 21) //一列 3 個兩頭沒堵
{
n =1 + A21;
m = 1 + x-1;
if(dangerlevel(A21,x-1) >= dangerlevel(A22,x-1))
qipan[A21][x-1] = 'x';
else
qipan[A22][x-1] = 'x';
}
else if(Num3 == 3&& A31 != 21 && A32 != 21) //一左上右下斜列3 個兩頭沒堵
{
n =1 + y + A31;
m = 1 + x + A31;
if(dangerlevel(y+A31,x+A31) >= dangerlevel(y-A32 - 2,y - A32 -2))
qipan[y+A31][x+A31] = 'x';
else
qipan[y-A32-2][x-A32 -2] = 'x';

}
else if(Num4==3 && A41 != 21 && A42 != 21) //一左下右上斜列3 個兩頭沒堵
{
n =1 + y - A41 - 2;
m = 1 + x + A41;
if(dangerlevel(y-A41-2,x+A41) >= dangerlevel(y-A42-2,x+A42))
qipan[y-A41-2][x+A41] = 'x';
else
qipan[y-A42-2][x+A42] = 'x';
}
else if(Num1 == 2&& A11 != 21 && A12 != 21) //一排2個兩頭沒堵
{
n =1 + y-1;
m = 1 + A11;
qipan[y-1][A11] = 'x';
}

else if( Num2 == 2&& A21 != 21 && A22 != 21) //一列2個兩頭沒堵
{
n =1 + A21;
m = 1 + x-1;
qipan[A21][x-1] = 'x';
}
else if(Num3 == 2&& A31 != 21 && A32 != 21) //一左上右下斜列2 個兩頭沒堵
{
n =1 + y + A31;
m = 1 + x + A31;
qipan[y+A31][x+A31] = 'x';
}
else if(Num4==2 && A41 != 21 && A42 != 21) //一左下右上斜列2個兩頭沒堵
{
n =1 + y - A41 - 2;
m = 1 + x + A41;
qipan[y-A41-2][x+A41] = 'x';
}
else
attack();
}

void five::showqipan()
{
int p=0,q=0;
for(int i = 0 ; i <= 20 ; i++)
{

if(p<10)
{
cout << p <<' ';
}
else
cout << p ;
p++;
}
cout << endl;
for(i = 0 ; i < 20 ; i++)
{
if(i>=0)
{
q++;
if(q<10)
cout << q <<' ';
else
cout << q;
}
for(int j = 0 ; j < 20 ; j ++)
cout << qipan[i][j]<<' ' ;

cout << endl;
}
}

void five::print()
{
int p=0,q=0;
for(int i = 0 ; i <= 20 ; i++)
{

if(p<10)
{
cout << p <<' ';
}
else
cout << p ;
p++;
}
cout << endl;
for(i = 0 ; i < 20 ; i++)
{
if(i>=0)
{
q++;
if(q<10)
cout << q <<' ';
else
cout << q;
}
for(int j = 0 ; j < 20 ; j ++)
{
cout << qipan[i][j]<<' ' ;
}

cout << endl;
}
}

bool five::IsxyWin()
{
int num1=1,num2=1,num3=1,num4=1;
for(int i = x ; i < x+5&& x+5<20 ; i ++)
{
if(qipan[y-1][i] != 'o')
break;
if(qipan[y-1][i] == 'o')
num1++;
}
for(i = x-2; i >= 0 ; i --)
{
if(qipan[y-1][i] != 'o')
break;
if(qipan[y-1][i] == 'o')
num1++;
}
for( i = y ; i < y+5 ; i ++)
{
if(qipan[i][x-1] != 'o')
break;
if(qipan[i][x-1] == 'o')
num2++;
}
for(i = y-2; i >= 0 ; i --)
{
if(qipan[i][x-1] != 'o')
break;
if(qipan[i][x-1] == 'o')
num2++;
}
for(i = 0 ; i < 5 && x+i<20 && y+i<20; i++ )
{
if(qipan[y+i][x+i] != 'o')
break;
if(qipan[y+i][x+i] =='o')
num3++;
}
for(i = 0 ; x - i -2>=0 && y-i-2>=0 && i < 5;i++ )
{
if(qipan[y-i-2][x-i-2] != 'o')
break;
if(qipan[y-i-2][x-i-2] == 'o')
num3++;
}
for(i = 0 ; x + i < 20 && y - i - 2 >= 0 && i < 5;i ++)
{
if(qipan[y-i-2][x+i] != 'o')
break;
if(qipan[y-i-2][x+i] == 'o')
num4++;
}
for(i = 0 ; y + i < 20 && x - i - 2 >= 0 && i < 5;i ++)
{
if(qipan[y+i][x-i-2] != 'o')
break;
if(qipan[y+i][x-i-2] == 'o')
num4++;
}
if(num1>=5||num2>=5||num3>=5||num4>=5)
return 1;
else
return 0;

}
bool five::IsmnWin()
{
int num1=1,num2=1,num3=1,num4=1;
for(int i = m ; i < m+5&& m+5<20 ; i ++)
{
if(qipan[n-1][i] != 'x')
break;
if(qipan[n-1][i] == 'x')
num1++;
}
for(i = m-2; i >= 0 ; i --)
{
if(qipan[n-1][i] != 'x')
break;
if(qipan[n-1][i] == 'x')
num1++;
}
for( i = n ; i < n+5 ; i ++)
{
if(qipan[i][m-1] != 'x')
break;
if(qipan[i][m-1] == 'x')
num2++;
}
for(i = n-2; i >= 0 ; i --)
{
if(qipan[i][m-1] != 'x')
break;
if(qipan[i][m-1] == 'x')
num2++;
}
for(i = 0 ; i < 5 && m+i<20 && n+i<20; i++ )
{
if(qipan[n+i][m+i] != 'x')
break;
if(qipan[n+i][m+i] =='x')
num3++;
}
for(i = 0 ; m - i -2>=0 && n-i-2>=0 && i < 5;i++ )
{
if(qipan[n-i-2][m-i-2] != 'x')
break;
if(qipan[n-i-2][m-i-2] == 'x')
num3++;
}
for(i = 0 ; m + i < 20 && n - i - 2 >= 0 && i < 5;i ++)
{
if(qipan[n-i-2][m+i] != 'x')
break;
if(qipan[n-i-2][m+i] == 'x')
num4++;
}
for(i = 0 ; n + i < 20 && m - i - 2 >= 0 && i < 5;i ++)
{
if(qipan[n+i][m-i-2] != 'x')
break;
if(qipan[n+i][m-i-2] == 'x')
num4++;
}
if(num1>=5||num2>=5||num3>=5||num4>=5)
return 1;
else
return 0;

}

void main()
{
five a;
int temp;
cout << "歡迎體驗本游戲!這是本游戲的棋盤:" << endl;
a.showqipan();
cout << "雙人游戲請按1,人機游戲請按2,退出請按3:";
cin >> temp;
if(temp == 3)
exit(1);
if(temp == 1)
{
cout << "您選擇了雙人游戲,下面游戲開始:" << endl;
for(int i = 0 ; ; i ++)
{
a.getpointxy();
a.print();
if(a.IsxyWin())
{
cout << "白棋勝!" << endl;
break;
}
a.getpointmn();
a.print();
if(a.IsmnWin())
{
cout << "黑棋勝!" << endl;
break;
}
}
}
if(temp == 2)
{
int temp1=0;
cout << "您選擇了人機游戲,您是白棋('o'),電腦是黑棋('x'),下面游戲開始:" << endl;
cout << "您先下請按1,電腦先下請按2:";
cin >> temp1;
if(temp1 == 1)
{
for(int i = 0 ; ; i ++)
{
a.getpointxy();
a.print();
if(a.IsxyWin())
{
cout << "你贏了!恭喜!" << endl;
break;
}
a.machinemn();
a.print();
cout << "電腦走(" << a.getm() << ',' << a.getn() << ')' << endl;
if(a.IsmnWin())
{
cout << "哈哈,你輸了!" << endl;
break;
}
}
}
if(temp1 == 2)
{
for(int i = 0 ; ; i ++)
{
a.machinemn();
a.print();
if(a.IsmnWin())
{
cout << "哈哈,你輸了!" << endl;
break;
}
a.getpointxy();
a.print();
if(a.IsxyWin())
{
cout << "你贏了!恭喜!" << endl;
break;
}

}
}
}
cout << "Press any key to EXIT\n";
getch();
}

熱點內容
安卓上哪裡下大型游戲 發布:2024-12-23 15:10:58 瀏覽:189
明日之後目前適用於什麼配置 發布:2024-12-23 14:56:09 瀏覽:54
php全形半形 發布:2024-12-23 14:55:17 瀏覽:828
手機上傳助手 發布:2024-12-23 14:55:14 瀏覽:732
什麼樣的主機配置吃雞開全效 發布:2024-12-23 14:55:13 瀏覽:830
安卓我的世界114版本有什麼 發布:2024-12-23 14:42:17 瀏覽:710
vbox源碼 發布:2024-12-23 14:41:32 瀏覽:278
詩經是怎麼存儲 發布:2024-12-23 14:41:29 瀏覽:660
屏蔽視頻廣告腳本 發布:2024-12-23 14:41:24 瀏覽:419
php解析pdf 發布:2024-12-23 14:40:01 瀏覽:818