交作业 交作业~

展开阅读全文

急着作业!请指教!

03-26

我们的数据结构作业,只能走一步,为什么?rnrn#include rn#pragma hdrstoprnrn//---------------------------------------------------------------------------rnrn#pragma argsusedrn#include rn#define X curpos.xrn#define Y curpos.yrnrn//迷宫rnint Maze[8][8]=rn 0,0,0,0,0,0,0,0,rn 0,1,0,0,1,0,1,0,rn 0,1,1,1,1,1,1,0,rn 0,0,0,1,0,0,1,0,rn 0,1,1,1,0,0,0,0,rn 0,1,0,0,1,1,1,0,rn 0,0,0,0,0,0,0,0;rnrn//定义堆栈rnstruct Postypern int x;rn int y;;rnstruct Stypern int ord;rn Postype seat;rn int dir;;rnstruct Listrn Stype v;rn struct List* next;;rntypedef struct List Node;rntypedef Node* Link;rnLink s;rnrnvoid push(Link s,Stype value)rnrn Link p;rn p=new Node;rn p->v=value;rn p->next=s;rn s=p;rnrnrnvoid pop(Link s,Stype& e)rnrn Link top;rn top=s;rn s=s->next;rn e=top->v;rn delete top;rnrnrn//改变位置rnPostype Nextpos(Postype p,int d)rnrn switch(d)rn rn case 1:rn p.x++;rn break;rn case 2:rn p.y++;rn break;rn case 3:rn p.x--;rn break;rn case 4:rn p.y--;rn break;rn rn return p;rnrnrn//走啊走rnint way(Postype start,Link s)rnrn Postype curpos=start;rn int curstep=1;rn Stype e;rnrn dorn if(Maze[X][Y]==1)rn rn Maze[X][Y]=2;rn e.ord=curstep;rn e.seat=curpos;rn e.dir=1;rn push(s,e);rn if (X==6&&Y==6)rn return 1;rn curpos=Nextpos(curpos,1);rn curstep++;rn rn else if(!s==NULL)rn rn pop(s,e);rn while (e.dir==4&&!s==NULL)rn rn Maze[X][Y]=3;rn pop(s,e);rn rn if (e.dir<4)rn rn e.dir++;rn push(s,e);rn curpos=Nextpos(e.seat,e.dir);rn rn rn while(!s==NULL);rn return 0;rnrnrnrn//打印rnvoid print(void)rnrn for(int i=0;i<=7;i++)rn rn for(int j=0;j<=7;j++)rn cout<>c;rnrn return 0;rnrn//---------------------------------------------------------------------------rnrn 论坛

明天作业,求帮助

11-24

1. 定义栈的存储结构,完成入栈、出栈、取栈顶、判断栈是否为空等基本操作的实现。rn2. 利用栈完成括号匹配算法。rn3. 主函数完成括号匹配算法的调用,实现对给定的括号序列进行匹配,给出匹配结果。rnrn半成品rn#include "stdio.h"rn#include"malloc.h"rn#include "stdlib.h" rn#include"conio.h"rn#define OK 1rn#define OVERFLOW -1rn#define ERROR 0rn#define STACK_INIT_SIZE 100rn#define STACKINCREMENT 10rntypedef int ElemType;rntypedef int Status;rn/*--------------栈的类型定义---------------*/rntypedef structrn ElemType *base;rn ElemType *top;rn int stacksize; rnSqStack;rn/*--------------构造一个空栈-------------*/rnStatus InitStack(SqStack *s)rnrn s->base=(ElemType *)malloc(STACK_INIT_SIZE * sizeof(ElemType));rn if(!s->base)exit(OVERFLOW);rn s->top=s->base;rn s->stacksize=STACK_INIT_SIZE;rn return OK;rnrn/*---------------取栈顶元素--------------*/rnStatus GetTop(SqStack*s, ElemType e)rnrn if(s->top==s->base)return ERROR;rn e=*(s->top-1);rn return OK;rnrn/*---------------压栈--------------------*/rnStatus Push(SqStack *s, ElemType e)rnrn if(s->top-s->base>=s->stacksize)rn rn s->base=(ElemType *)realloc(s->base,(s->stacksize+STACKINCREMENT)*sizeof(ElemType));rn if(!s->base)exit(OVERFLOW);rn s->top=s->base+s->stacksize;rn s->stacksize+=STACKINCREMENT;rn rn *s->top++=e;rn return OK;rnrn/*--------------出栈-------------------*/rnStatus Pop(SqStack *s, ElemType e)rnrn if(s->top==s->base)return ERROR;rn e=*--s->top;rn return e;rnrnrn rnrn/*------------------主函数-----------------*/rnvoid main()rnrn SqStack s;rn int e;rn InitStack(&s);rn rn rnrngetch();rnrnrnrnrn 论坛

作业了!求指错,谢谢!

03-19

前些日子在这里问的问题,是关于一个玩骰子的小游戏,基本就是3个骰子,有20多种赢法,每种赢法的赔率也不一样。rnrn第一次接触c#,也基本算是做完了,但是代码写的肯定差的不得了,我尽量简化和消除bug,忘各位朋友给看看指出不足,在此多谢了!rnrn[code=csharp]rnusing System;rnusing System.Collections.Generic;rnusing System.Linq;rnusing System.Text;rnusing System.Text.RegularExpressions;rnrnnamespace ConsoleApplication1rnrn class Programrn rn static void Main(string[] args)rn rn // declare variables.rn string userChoiceString = ""; // make sure players can only enter numberrnrn string userWagerString = ""; // make sure players can only enter numberrnrn string playerName; // players need to enter their namernrn int userBalance = 200;rnrn int userChoice;rnrn int userWager;rnrn // store all bet types and odds into a arrayrnrn int[] odds = 1, 1, 1, 1, 180, 180, 180, 180, 180, 180, 10, 10, 10, 10, 10, 10, 30, 60, 30, 18, 12, 8, 7, 6 ;rnrn string[] betTypes = "\"Big\"", "\"Small\"", "\"Odd\"", "\"Even\"", "\"All 1s\"", "\"All 2s\"",rn "\"All 3s\"", "\"All 4s\"", "\"All 5s\"", "\"All 6s\"", "\"Double 1s\"", "\"Double 2s\"",rn "\"Double 3s\"", "\"Double 4s\"", "\"Double 5s\"", "\"Double 6s\"", "\"Any triples\"", "\"4 or 17\"", rn "\"5 or 16\"", "\"6 or 15\"", "\"7 or 14\"", "\"8 or 13\"", "\"9 or 12\"", "\"10 or 11\"", ;rnrn // intro textrn Console.ForegroundColor = ConsoleColor.Yellow;rn Console.WriteLine("\n\n\n Welcome to Lewis's Back Alley Dice Game !\n\n");rn Console.ResetColor();rnrn Console.WriteLine(" Press any key to start ...\n");rn Console.ReadKey();rn Console.Clear();rnrn Console.Write("\n\n\n Please enter your name : ");rn Console.ForegroundColor = ConsoleColor.Yellow;rn playerName = Console.ReadLine();rn Console.ResetColor();rnrn // main game loop rn while (userBalance>0 && userBalance<1000)rn rn // declare 3 random dicesrn Random ran = new Random();rnrn int dice1 = ran.Next(1, 7);rnrn int dice2 = ran.Next(1, 7);rnrn int dice3 = ran.Next(1, 7);rnrn // isTrue = true != triplern bool isTrue = dice1 != dice2 || dice2 != dice3;rnrn int sum = dice1 + dice2 + dice3;rnrn Console.Write("\n\n\n Hi 0 ! You have : ", playerName);rnrn Console.ForegroundColor = ConsoleColor.Red;rn Console.WriteLine("$0\n", userBalance);rn Console.ResetColor();rnrn Console.WriteLine("================================================================================");rn Console.ForegroundColor = ConsoleColor.DarkCyan;rn Console.WriteLine(@"Bet Types:rnrn 1 = Big 2 = Small 3 = Odd 4 = Even 5 = All 1s rn 6 = All 2s 7 = All 3s 8 = All 4s 9 = All 5s 10 = All 6s rn rn11 = Double 1s 12 = Double 2s 13 = Double 3s 14 = Double 4s 15 = Double 5s rn16 = Double 6s 17 = Any triples 18 = 4 or 17 19 = 5 or 16 20 = 6 or 15 rnrn21 = 7 or 14 22 = 8 or 13 23 = 9 or 12 24 = 10 or 11 rnrn ");rn Console.ResetColor();rn Console.WriteLine("================================================================================\n");rnrn Console.WriteLine(" Mao : What bet would you like to make ?\n");rnrn Console.Write(" Mao : Please enter a number between ");rn Console.ForegroundColor = ConsoleColor.Yellow;rn Console.Write("1 ~ 24");rn Console.ResetColor();rn Console.Write(" : ");rn Console.ForegroundColor = ConsoleColor.Green;rn userChoiceString = Console.ReadLine();rn Console.ResetColor();rn Console.WriteLine();rnrn while (!IsNum(userChoiceString))rn rn Console.Write(" Mao : I said ");rn Console.ForegroundColor = ConsoleColor.Yellow;rn Console.Write("Number, NUMBER");rn Console.ResetColor();rn Console.WriteLine(" !\n");rn Console.Write(" Mao : Please enter a number between ");rn Console.ForegroundColor = ConsoleColor.Yellow;rn Console.Write("1 ~ 24");rn Console.ResetColor();rn Console.Write(" : ");rn Console.ForegroundColor = ConsoleColor.Green;rn userChoiceString = Console.ReadLine();rn Console.ResetColor();rn Console.WriteLine();rn rnrn userChoice = int.Parse(userChoiceString);rnrn while (userChoice > 24 || userChoice < 0)rn rn Console.WriteLine(" Mao : Oh My God! I said number between 1 ~ 24, do you understand? \n");rn userChoice = ran.Next(1,25);rn Console.Write(" Mao : NVM, I will choice a number for you randomly : ");rn Console.ForegroundColor = ConsoleColor.Green;rn Console.WriteLine(userChoice);rn Console.ResetColor();rn Console.WriteLine();rn rnrn Console.Write(" Mao : You selected ");rn Console.ForegroundColor = ConsoleColor.DarkCyan;rn Console.Write(betTypes[userChoice - 1]);rn Console.ResetColor();rn Console.WriteLine(" , how much would you like to bet?\n");rn Console.Write(" Mao : Remember ");rn Console.ForegroundColor = ConsoleColor.Yellow;rn Console.Write("money = number ");rn Console.ResetColor();rn Console.Write(", enter a amount : ");rnrn Console.ForegroundColor = ConsoleColor.Red;rn userWagerString = Console.ReadLine();rn Console.ResetColor();rn Console.WriteLine();rnrn while (!IsNum(userWagerString))rn rn Console.Write(" Mao : I said ");rn Console.ForegroundColor = ConsoleColor.Yellow;rn Console.Write("money = number ");rn Console.ResetColor();rn Console.WriteLine(" !\n");rn Console.Write(" Mao : Please enter another amount : "); rn Console.ForegroundColor = ConsoleColor.Red;rn userWagerString = Console.ReadLine();rn Console.ResetColor();rn Console.WriteLine();rn rn rn userWager = int.Parse(userWagerString);rn rn while (userWager > userBalance)rn rn Console.Write(" Mao : Oh You don't have enough money, throw all you have : ");rn userWager = userBalance;rn Console.ForegroundColor = ConsoleColor.Red;rn Console.Write(userBalance);rn Console.ResetColor();rn Console.WriteLine();rn rnrn Console.WriteLine(@"rn Mao : Finally ! OK, Lets roll !rnrn =================== rn Rolling dice ... rn rn Dice 1: 0rn Dice 2: 1 rn Dice 2: 2rn rn Sum: 3 rn =================== rnrn", dice1, dice2, dice3, sum);rnrn switch (userChoice)rn rn case 1: // User selected "Big"rn if (sum > 10 && sum < 18 && isTrue)rn rn userWin(ref userBalance, ref userChoice, ref userWager, ref odds);rn rn elsern rn userLose(ref userBalance, ref userWager);rn rn break;rnrn case 2: // User selected "Small"rnrn if (sum > 4 && sum < 11 && isTrue)rn rn userWin(ref userBalance, ref userChoice, ref userWager, ref odds);rn rn elsern rn userLose(ref userBalance, ref userWager);rn rn break;rnrn case 3: // User selected "Odd"rnrn if (sum % 2 == 1 && isTrue)rn rn userWin(ref userBalance, ref userChoice, ref userWager, ref odds);rn rn elsern rn userLose(ref userBalance, ref userWager);rn rn break;rnrn case 4: // User selected "Even"rnrn if (sum % 2 == 0 && isTrue)rn rn userWin(ref userBalance, ref userChoice, ref userWager, ref odds);rn rn elsern rn userLose(ref userBalance, ref userWager);rn rn break;rnrn case 17: // User selected "Any Triples"rnrn if (isTrue)rn rn userLose(ref userBalance, ref userWager);rn rn elsern rn userWin(ref userBalance, ref userChoice, ref userWager, ref odds);rn rn break;rnrn rnrn 论坛

没有更多推荐了,返回首页