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

首頁 > 學院 > 開發設計 > 正文

poj1208

2019-11-11 02:33:40
字體:
來源:轉載
供稿:網友

題目大意:

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

解題思路:

模擬題,分別寫4個函數模擬這個過程即可

代碼如下:

#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++) {
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 白山市| 师宗县| 安岳县| 九龙坡区| 城步| 安乡县| 延边| 密山市| 龙山县| 富锦市| 修水县| 龙州县| 蒙自县| 江永县| 绩溪县| 石景山区| 沈阳市| 大理市| 丹东市| 汕尾市| 石屏县| 天祝| 昭通市| 城步| 荥经县| 琼结县| 禹城市| 团风县| 高阳县| 峨边| 织金县| 应城市| 平阳县| 布拖县| 鱼台县| 长春市| 师宗县| 桂平市| 南江县| 齐河县| 文化|