大佬急求

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_40082518/article/details/84978742

这里有个bug需要大佬帮忙指点改一下,急急急
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include <conio.h>

/测控17-2班 在这里插入图片描述。。。。。。/

void welcome2018()
{
int a,n=0;
printf("*****************************来了老弟?*********************\n\n");
printf("你好,我是小智,真好!
\n\n");
printf("这有个五子棋游戏,爱玩不玩
\n\n");
printf("想玩就必须召唤三只皮卡丘
\n\n");
printf("下雪了!买了佛冷!
\n\n");
printf("************************请输入你的召唤密码:");
while(n<3)
{
scanf("%d",&a);
if(a>=66)
{
printf(“这是一只皮卡丘\n”);
n++;
}
else
printf(“这是一只妙蛙种子\n”);
}
printf("\n");
printf(“恭喜您召唤成功,游戏即将开启…”);
Sleep(2000) ;//暂停两秒
system(“cls”);//清屏
char e; int f;
printf("\t欢迎来到孙哲韦版五子棋寻宝之旅\n\n");
printf("\t请先注册一个id\n\n");
printf("\t\t用户名(姓名):");
scanf("%s",&e);
printf("\n\t\t密码(学号)😊;
scanf("%d",&f);
printf("\n\n\t注册成功,寻宝之旅即将开始…\n\n");
Sleep(3000);
}

int main()
{
welcome2018();

char y;
 int i, j, m = 7, n = 7, g = 1, f,w;
  int a[15][15] = { 0 };
   a[m][n] = -1;
                                    
do
{
	for (j = 0; j<15; j++)

	{
		for (i = 0; i<15; i++)

			switch (a[i][j])
		{
			case 0:printf("十"); break;
			case -1:printf("×"); break;
			case 1:printf("○"); break;
			case 2:printf("●");break;
		}
		printf("\n");
	
	}	 

printf(“按‘W’向上移动一格\t”); printf(“按‘S’向下移动一格\n”);
printf(“按‘A’向左移动一格\t”); printf(“按‘D’向右移动一格\n”);
printf(“按‘空格’落子\t\t”); printf(“按‘Q’退出游戏\n”);
f = (g % 2);
if(w!=1&&w!=2) {if(f!=1)printf(“请二号玩家黑棋落子:\n”);
else printf(“请一号玩家白棋落子:\n”);}

	y = getch();
	if (a[m][n] == -1)a[m][n] = 0;
	switch (y)
	{
	  case'a':m--; if (m == -1)m = 14; else;if (a[m][n] == 0)a[m][n] = -1; break;
		  
	  case'd':m++; if (m == 15)m = 0; else; if (a[m][n] == 0)a[m][n] = -1; break;
		 
	  case'w':n--; if (n == -1)m = 14; else; if (a[m][n] == 0)a[m][n] = -1; break;
		 
	  case's':n++; if (n == 15)m = 0; else; if (a[m][n] == 0)a[m][n] = -1; break;
		 
	  case' ': if (a[m][n] == 0){ if (f == 0)a[m][n] = 1;else a[m][n] = 2; g++; }else; break;//空格
	}
		
	system("cls");
	
	{
	if(a[m][n]==2&&a[m+1][n]==2&&a[m+2][n]==2&&a[m+3][n]==2&&a[m+4][n]==2)w=1;
	if(a[m][n]==2&&a[m+1][n]==2&&a[m+2][n]==2&&a[m+3][n]==2&&a[m-1][n]==2)w=1;
	if(a[m][n]==2&&a[m+1][n]==2&&a[m+2][n]==2&&a[m-1][n]==2&&a[m-2][n]==2)w=1;
	if(a[m][n]==2&&a[m+1][n]==2&&a[m-1][n]==2&&a[m-2][n]==2&&a[m-3][n]==2)w=1;
	if(a[m][n]==2&&a[m-1][n]==2&&a[m-2][n]==2&&a[m-3][n]==2&&a[m-4][n]==2)w=1;
	if(a[m][n]==2&&a[m][n+1]==2&&a[m][n+2]==2&&a[m][n+3]==2&&a[m][n+4]==2)w=1;
	if(a[m][n]==2&&a[m][n+1]==2&&a[m][n+2]==2&&a[m][n+3]==2&&a[m][n-1]==2)w=1;
	if(a[m][n]==2&&a[m][n+1]==2&&a[m][n+2]==2&&a[m][n-1]==2&&a[m][n-2]==2)w=1;
	if(a[m][n]==2&&a[m][n+1]==2&&a[m][n-1]==2&&a[m][n-2]==2&&a[m][n-3]==2)w=1;
	if(a[m][n]==2&&a[m][n-1]==2&&a[m][n-2]==2&&a[m][n-3]==2&&a[m][n-4]==2)w=1;
	if(a[m][n]==2&&a[m+1][n+1]==2&&a[m+2][n+2]==2&&a[m+3][n+3]==2&&a[m+4][n+4]==2)w=1;
	if(a[m][n]==2&&a[m+1][n+1]==2&&a[m+2][n+2]==2&&a[m+3][n+3]==2&&a[m-1][n-1]==2)w=1;
	if(a[m][n]==2&&a[m+1][n+1]==2&&a[m+2][n+2]==2&&a[m-1][n-1]==2&&a[m-2][n-2]==2)w=1;
	if(a[m][n]==2&&a[m+1][n+1]==2&&a[m-1][n-1]==2&&a[m-2][n-2]==2&&a[m-3][n-3]==2)w=1;
	if(a[m][n]==2&&a[m-1][n-1]==2&&a[m-2][n-2]==2&&a[m-3][n-3]==2&&a[m-4][n-4]==2)w=1; 
	if(a[m][n]==2&&a[m-1][n+1]==2&&a[m-2][n+2]==2&&a[m-3][n+3]==2&&a[m-4][n+4]==2)w=1;
	if(a[m][n]==2&&a[m-1][n+1]==2&&a[m-2][n+2]==2&&a[m-3][n+3]==2&&a[m+1][n-1]==2)w=1;
	if(a[m][n]==2&&a[m-1][n+1]==2&&a[m-2][n+2]==2&&a[m+1][n-1]==2&&a[m+2][n-2]==2)w=1;
	if(a[m][n]==2&&a[m-1][n+1]==2&&a[m+1][n-1]==2&&a[m+2][n-2]==2&&a[m+3][n-3]==2)w=1;
	if(a[m][n]==2&&a[m+1][n-1]==2&&a[m+2][n-2]==2&&a[m+3][n-3]==2&&a[m+4][n-4]==2)w=1;  
	
	
	
	
	
	if(a[m][n]==1&&a[m+1][n]==1&&a[m+2][n]==1&&a[m+3][n]==1&&a[m+4][n]==1)w=2;
	if(a[m][n]==1&&a[m+1][n]==1&&a[m+2][n]==1&&a[m+3][n]==1&&a[m-1][n]==1)w=2;
	if(a[m][n]==1&&a[m+1][n]==1&&a[m+2][n]==1&&a[m-1][n]==1&&a[m-2][n]==1)w=2;
	if(a[m][n]==1&&a[m+1][n]==1&&a[m-1][n]==1&&a[m-2][n]==1&&a[m-3][n]==1)w=2;
	if(a[m][n]==1&&a[m-1][n]==1&&a[m-2][n]==1&&a[m-3][n]==1&&a[m-4][n]==1)w=2; 
	if(a[m][n]==1&&a[m][n+1]==1&&a[m][n+2]==1&&a[m][n+3]==1&&a[m][n+4]==1)w=2;
	if(a[m][n]==1&&a[m][n+1]==1&&a[m][n+2]==1&&a[m][n+3]==1&&a[m][n-1]==1)w=2;
	if(a[m][n]==1&&a[m][n+1]==1&&a[m][n+2]==1&&a[m][n-1]==1&&a[m][n-2]==1)w=2;
	if(a[m][n]==1&&a[m][n+1]==1&&a[m][n-1]==1&&a[m][n-2]==1&&a[m][n-3]==1)w=2;
	if(a[m][n]==1&&a[m][n-1]==1&&a[m][n-2]==1&&a[m][n-3]==1&&a[m][n-4]==1)w=2; 
	if(a[m][n]==1&&a[m+1][n+1]==1&&a[m+2][n+2]==1&&a[m+3][n+3]==1&&a[m+4][n+4]==1)w=2;
	if(a[m][n]==1&&a[m+1][n+1]==1&&a[m+2][n+2]==1&&a[m+3][n+3]==1&&a[m-1][n-1]==1)w=2;
	if(a[m][n]==1&&a[m+1][n+1]==1&&a[m+2][n+2]==1&&a[m-1][n-1]==1&&a[m-2][n-2]==1)w=2;
	if(a[m][n]==1&&a[m+1][n+1]==1&&a[m-1][n-1]==1&&a[m-2][n-2]==1&&a[m-3][n-3]==1)w=2;
	if(a[m][n]==1&&a[m-1][n-1]==1&&a[m-2][n-2]==1&&a[m-3][n-3]==1&&a[m-4][n-4]==1)w=2; 
	if(a[m][n]==1&&a[m-1][n+1]==1&&a[m-2][n+2]==1&&a[m-3][n+3]==1&&a[m-4][n+4]==1)w=2;
	if(a[m][n]==1&&a[m-1][n+1]==1&&a[m-2][n+2]==1&&a[m-3][n+3]==1&&a[m+1][n-1]==1)w=2;
	if(a[m][n]==1&&a[m-1][n+1]==1&&a[m-2][n+2]==1&&a[m+1][n-1]==1&&a[m+2][n-2]==1)w=2;
	if(a[m][n]==1&&a[m-1][n+1]==1&&a[m+1][n-1]==1&&a[m+2][n-2]==1&&a[m+3][n-3]==1)w=2;
	if(a[m][n]==1&&a[m+1][n-1]==1&&a[m+2][n-2]==1&&a[m+3][n-3]==1&&a[m+4][n-4]==1)w=2;
	}

if(w1)
printf("\n 恭喜一号玩家获得胜利!\n\t 请按Q退出\n\n\n");
if(w
2)
printf("\n 恭喜二号玩家获得胜利!\n\t 请按Q退出\n\n\n");}

 while (y != 'q'); 

return 0;
}

展开阅读全文

小弟菜鸟初学者,大佬解答,

12-04

期末写的snake项目,写到下面的时候发现显示不了了rnpackage com.snake;rnrnimport javax.swing.JFrame;rnrnpublic class SnakeJFrame extends JFrame rn public SnakeJFrame() rn initframe();rn SnakeJPanel sJPanel = new SnakeJPanel();rn rn this.add(sJPanel);rn rn public void initframe() rn this.setTitle("5");rn this.setSize(800,800);rn this.setLocationRelativeTo(null);rn this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);rn this.setVisible(true);rn rn public static void main(String[] args) rn new SnakeJFrame();rn rnrnrnrnrnrnrnrnrnpackage com.snake;rnrnimport java.awt.Color;rnimport java.awt.Graphics;rnimport java.awt.event.KeyEvent;rnimport java.awt.event.KeyListener;rnrnimport javax.swing.JPanel;rnrnpublic class SnakeJPanel extends JPanel implements KeyListenerrn rn Snake snake =new Snake();rn Food food = new Food();rn public SnakeJPanel() rn startGame();rn rnrn rn private void startGame() rn // TODO Auto-generated method stubrn new Thread()rn public void run() rn while(true)rn snake.snakeMove();rn try rn Thread.sleep(300);rn catch (InterruptedException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn repaint();rn rn ;rn .start();rn rn rnrnrn @Overridern protected void paintComponent(Graphics g) rn // TODO Auto-generated method stubrn super.paintComponent(g);rn System.out.println("显示");rn setBackground(Color.gray);rn g.setColor(Color.RED);rn g.drawRect(100, 100, 600, 600);rn g.setColor(Color.WHITE);rn g.fillRect(100, 100, 600, 600);rn if(snake!=null&&food!=null)rn snake.drawSnake(g);rn food.drawFood(g);rn rn rn rnrnrn @Overridern public void keyPressed(KeyEvent e) rn // TODO Auto-generated method stubrn System.out.println("拿了");rn rn rnrnrn @Overridern public void keyReleased(KeyEvent e) rn // TODO Auto-generated method stubrn rn rnrnrn @Overridern public void keyTyped(KeyEvent e) rn // TODO Auto-generated method stubrn rn rnrnrnrnrnrnpackage com.snake;rnrnimport java.awt.Color;rnimport java.awt.Graphics;rnimport java.awt.Point;rnimport java.util.LinkedList;rnrnpublic class Snake rn int snakex = 400, snakey = 400;rn LinkedList body = new LinkedList<>();rn final static int up = 1, down = -1, left = 2, right = -2, direction = -2;rnrn public Snake() rn initBody();rn rn rnrn public void snakeMove() rn System.out.println("蛇正在移动");rn int x = body.getFirst().x;rn int y = body.getFirst().y;rn switch (direction) rn case up:rn y--;rn body.addFirst(new Point(x, y));rn break;rn case down:rn y++;rn body.addFirst(new Point(x, y));rn break;rn case left:rn x--;rn body.addFirst(new Point(x, y));rn break;rn case right:rn x++;rn body.addFirst(new Point(x, y));rn break;rnrn rnrn rnrn public void initBody() rn for (int i = 0; i < 3; i++) rn body.add(new Point(snakex + i * 10, snakey));rn rn rnrn public void drawSnake(Graphics g) rn System.out.println("蛇正在绘制");rn g.setColor(Color.GREEN);rn for (int i = 0; i < body.size(); i++) rn g.fillRect(body.get(i).x, body.get(i).y, 10, 10);rn rn rnrnrnrnrnrnrnrnrnpackage com.snake;rnrnimport java.awt.Color;rnimport java.awt.Graphics;rnrnpublic class Food rn int Foodx = (int) (Math.random() * 600) + 100;rn int Foody = (int) (Math.random() * 600) + 100;rn rn public void drawFood(Graphics g) rn // TODO Auto-generated method stubrn System.out.println("食物正在绘制");rn g.setColor(Color.red);rn g.fillRect(Foodx, Foody, 10, 10);rn rnrnrn 论坛

大佬们解答!!!

08-31

刚做了一道华为的测试题,不知道为啥,提交上去说我通过率只有20%,求解!!!rnrn[size=18px][b]题目:[/b][/size]rn给定一个整数,给出消除重复数字以后最大的整数rnrn输入描述:rnrn正整数,注意考虑长整数rnrn输出描述rnrn消除重复数字后的最大整数rnrn示例1rnrn输入rnrn423234rnrn输出rnrn432rnrn[size=18px][b]疑问:[/b][/size]rn1、题目中说到:注意考虑长整数是什么意思?rn2、请大佬们指出我的代码问题出来哪里,为什么只有20%通过率,哪些范围的数字通不过?rnrn附上我自己的代码,不明白为什么通过率只有20%:rn#include rn#include rnrnint num[100];rnrnvoid sort(int a[], int n) rnrn int i,j,k,t;rn for(i = 0; i < n - 1; ++i) rn rn k = i;rn for(j = i + 1; j < n; ++j) rn rn if(a[k] < a[j])rn k = j;rn rn if(i != k) rn rn t = a[i];rn a[i] = a[k];rn a[k] = t;rn rn rnrnrnint xiaochu(int a[], int n) rnrn int i,j,k;rn for(i = 0; i < n - 1; ++i) rn rn for(j = i + 1; j < n; ++j) rn rn if(a[i] == a[j])rn rn for(k = j; k < n - 1; ++k)rn rn a[k] = a[k + 1];rn rn --n;rn --j;rn rn rn rn return n;rnrnrnint main(void)rnrn long a = 423234;rn int i = 0;rnrn while(a)rn rn num[i] = a % 10;rn a = a / 10;rn i++;rn rnrn sort(num, i);rn int count = xiaochu(num, i);rnrn int temp = 0;rnrn for(int j = 0; j < count; j++)rn temp = temp * 10 + num[j];rnrn printf("%d\n", temp);rn //system("pause");rnrn return 0;rnrnrn这段代码我在考试的网页上点击自测,但是网上给出的答案是:rn[img=https://img-bbs.csdn.net/upload/201808/31/1535696754_819035.png][/img]rn但是自己在VS2010中编译计算后的结果是:rn[img=https://img-bbs.csdn.net/upload/201808/31/1535696864_511655.jpg][/img] 论坛

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