国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

poj1208

2019-11-11 00:35:02
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

題目大意:

按照4條指令搬運(yùn)積木即可。 1、move a onto b 在將a搬到b上之前,先將a和b上的積木放回原來(lái)的位置(例如:1就放回1的最開(kāi)始位罝) 2、move a over b 在將a搬到b所在的那堆積木上前,先將a上的積木放回原來(lái)的位罝(b所在的那堆不動(dòng)) 3、pile a onto b 將a本身和其上的積木一起放到b上,在搬之前b上方的積木放回原位 4、pile a over b 將a本身和其上的積木一起搬到到b所在的那堆上 5、quit 結(jié)束命令,前四個(gè)動(dòng)作中若a=b,或者a, b在同一堆中,該動(dòng)作不合法,不做改變。

解題思路:

模擬題,分別寫4個(gè)函數(shù)模擬這個(gè)過(guò)程即可

代碼如下:

#include<stdio.h>#include<stdlib.h>#include<string.h>typedef struct{ int len; int stack;}pos;int num[30][30],len[30],n,a,b;pos p[30];char ch1[20],ch2[20];void moveonto(){ int i,j,x,y; x=p[a].stack;y=p[a].len; for(i=y+1;i<=len[x];i++) { num[num[x][i]][++len[num[x][i]]]=num[x][i]; p[num[x][i]].len=len[num[x][i]]; p[num[x][i]].stack=num[x][i]; } num[p[b].stack][++len[p[b].stack]]=a; p[a].len=len[p[b].stack]; p[a].stack=p[b].stack; len[x]=y-1;}void moveover(){ int i,j,x,y; x=p[a].stack;y=p[a].len; for(i=y+1;i<=len[x];i++) { num[num[x][i]][++len[num[x][i]]]=num[x][i]; p[num[x][i]].len=len[num[x][i]]; p[num[x][i]].stack=num[x][i]; } num[p[b].stack][++len[p[b].stack]]=a; p[a].len=len[p[b].stack]; p[a].stack=p[b].stack; len[x]=y-1;}void pileover(){ int i,j,x,y; x=p[a].stack;y=p[a].len; for(i=y;i<=len[x];i++) { num[p[b].stack][++len[p[b].stack]]=num[x][i]; p[num[x][i]].len=len[p[b].stack]; p[num[x][i]].stack=p[b].stack; } len[x]=y-1;}void pileonto(){ int i,j,x,y; x=p[b].stack;y=p[b].len; for(i=y+1;i<=len[x];i++) { num[num[x][i]][++len[num[x][i]]]=num[x][i]; p[num[x][i]].len=len[num[x][i]]; p[num[x][i]].stack=num[x][i]; } len[x]=y; x=p[a].stack;y=p[a].len; for(i=y;i<=len[x];i++) { num[p[b].stack][++len[p[b].stack]]=num[x][i]; p[num[x][i]].len=len[p[b].stack]; p[num[x][i]].stack=p[b].stack; } len[x]=y-1;}int main(){ int i,j; scanf("%d",&n); for(i=0;i<n;i++) { p[i].len=1; p[i].stack=i; len[i]=1; num[i][1]=i; } while(scanf("%s",ch1)!=EOF&&(strcmp(ch1,"quit"))) { scanf("%d%s%d",&a,ch2,&b); if((!strcmp(ch1,"move"))&&(!strcmp(ch2,"onto"))) { if(a==b||(p[a].stack==p[b].stack)) { continue; } moveonto(); } if((!strcmp(ch1,"move"))&&(!strcmp(ch2,"over"))) { if(a==b||(p[a].stack==p[b].stack)) { continue; } moveover(); } if((!strcmp(ch1,"pile"))&&(!strcmp(ch2,"onto"))) { if(a==b||(p[a].stack==p[b].stack)) { continue; } pileonto(); } if((!strcmp(ch1,"pile"))&&(!strcmp(ch2,"over"))) { if(a==b||(p[a].stack==p[b].stack)) { continue; } pileover(); } } for(i=0;i<n;i++) {
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 纳雍县| 碌曲县| 景泰县| 井陉县| 固原市| 华容县| 大港区| 娄底市| 山阴县| 韶山市| 乳源| 霍州市| 吉木萨尔县| 安平县| 卢湾区| 义乌市| 昌吉市| 壤塘县| 汉川市| 镇赉县| 顺昌县| 鹿泉市| 洪洞县| 曲阜市| 扎兰屯市| 招远市| 隆尧县| 泰和县| 武定县| 松滋市| 元江| 吉木萨尔县| 天门市| 安图县| 扎囊县| 乃东县| 全南县| 温泉县| 巩义市| 基隆市| 龙井市|