cf246A. Buggy Sorting

题目链接:点击打开链接

#include<stdio.h>
int main()
{
int n,i;
while(~scanf("%d",&n))
{
if(n<=2)
printf("-1\n");
else
{
printf("%d %d",n-1,n);
for(i=1;i<=n-2;i++)
printf(" %d",i);
printf("\n");
}
}
return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是 Moon-Buggy 的代码: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <signal.h> #include <curses.h> #include <time.h> #define VERSION "1.0" #define MAX(x,y) ((x) > (y) ? (x) : (y)) #define MIN(x,y) ((x) < (y) ? (x) : (y)) #define WIDTH 64 #define HEIGHT 16 #define PLAYER_POS_X 4 #define PLAYER_POS_Y (HEIGHT-3) #define DISTANCE_PER_FRAME 8 #define OBSTACLE_PERIOD 8 #define JUMP_DURATION 12 #define JUMP_HEIGHT 3 #define GRAVITY 1 #define SPRITE_GAP 2 static char player_up[] = {'O',0,'-','^',0,'|',0,0,'|',0,'^',0,'-',0,'O',0}; static char player_down[] = {'O',0,'-','v',0,'|',0,0,'|',0,'v',0,'-',0,'O',0}; static char obstacle1[] = {'*',' ',' ',0,'*','*',0,'*',' ',0,'*','*',0,'*',' ',0,'*',0}; static char obstacle2[] = {'*',0,0,'*',' ',0,'*','*',0,'*','*',0,'*',' ',0,'*',0,0}; static char *obstacles[] = {obstacle1, obstacle2}; static int sprite_widths[] = {16, 17}; static int obstacle_probabilities[] = {60, 40}; static int obstacle_y[] = {HEIGHT-3, HEIGHT-4}; static char *title[] = { "", " Moon Buggy", "", "", "", " Press SPACE to start", " Press Q to quit", "", " Version " VERSION, "", "", "", "", "", "", NULL }; static char *gameover[] = { "", "", "", " GAME OVER", "", "", "", " Press SPACE to restart", " Press Q to quit", "", "", "", "", "", "", NULL }; static char *score_prefix[] = { "SCORE: ", NULL }; static char score[16]; static int obstacle_pos = WIDTH-1; static int obstacle_type = 0; static int obstacle_speed = 1; static int obstacle_visible = 0; static int player_pos_y = PLAYER_POS_Y; static int player_speed_y = 0; static int player_jump_remaining = 0; static int distance = 0; static int score_length; static int frame_count = 0; static int frame_rate = 20; static int frame_period = 1000/frame_rate; static int screen_width = WIDTH+1; static int screen_height = HEIGHT+4; static WINDOW *win; static void draw_sprite(int x, int y, char *sprite, int width) { int i, j; for (i = 0; i < width; i++) { if (sprite[i]) { mvwaddch(win, y, x+i, sprite[i]); } } } static void draw_title() { int i; int y = (screen_height - sizeof(title)/sizeof(title[0])) / 2; for (i = 0; title[i]; i++) { mvwaddstr(win, y+i, (screen_width-strlen(title[i]))/2, title[i]); } } static void draw_gameover() { int i; int y = (screen_height - sizeof(gameover)/sizeof(gameover[0])) / 2; for (i = 0; gameover[i]; i++) { mvwaddstr(win, y+i, (screen_width-strlen(gameover[i]))/2, gameover[i]); } } static void draw_score() { sprintf(score, "%d", distance); mvwaddstr(win, 0, screen_width-score_length-1, score_prefix[0]); wattron(win, A_REVERSE); mvwaddstr(win, 0, screen_width-score_length-1+strlen(score_prefix[0]), score); wattroff(win, A_REVERSE); } static void draw_player() { if (player_jump_remaining) { draw_sprite(PLAYER_POS_X, player_pos_y, player_up, sprite_widths[0]); } else { draw_sprite(PLAYER_POS_X, player_pos_y, player_down, sprite_widths[1]); } } static void draw_obstacle() { if (obstacle_visible) { draw_sprite(obstacle_pos, obstacle_y[obstacle_type], obstacles[obstacle_type], sprite_widths[obstacle_type]); } } static void draw() { werase(win); draw_score(); draw_player(); draw_obstacle(); wrefresh(win); } static void update_player() { if (player_jump_remaining) { player_pos_y -= player_speed_y; player_speed_y -= GRAVITY; if (player_pos_y >= PLAYER_POS_Y) { player_jump_remaining = 0; player_pos_y = PLAYER_POS_Y; player_speed_y = 0; } } } static void update_obstacle() { if (++frame_count % OBSTACLE_PERIOD == 0) { if (!obstacle_visible) { obstacle_visible = 1; obstacle_type = rand() % 2; obstacle_pos = WIDTH - sprite_widths[obstacle_type]; obstacle_speed = 1 + rand() % 3; } } if (obstacle_visible) { obstacle_pos -= obstacle_speed; if (obstacle_pos < -sprite_widths[obstacle_type]) { obstacle_visible = 0; } } } static void update_distance() { distance += DISTANCE_PER_FRAME; score_length = strlen(score_prefix[0]) + strlen(score); } static void handle_input() { int c = getch(); if (c == ' ') { if (player_pos_y == PLAYER_POS_Y) { player_jump_remaining = JUMP_DURATION; player_speed_y = JUMP_HEIGHT; } else if (!obstacle_visible) { distance = 0; } } else if (c == 'q') { endwin(); exit(0); } } static void init() { initscr(); cbreak(); noecho(); curs_set(0); nodelay(stdscr, TRUE); win = newwin(screen_height, screen_width, 0, 0); srand(time(NULL)); } static void cleanup() { delwin(win); endwin(); } static void game_loop() { for (;;) { update_player(); update_obstacle(); update_distance(); draw(); handle_input(); if (player_pos_y == PLAYER_POS_Y && obstacle_visible && obstacle_type == 0 && obstacle_pos == PLAYER_POS_X && obstacle_y[0] == PLAYER_POS_Y) { draw_gameover(); wrefresh(win); while (getch() != ' ') { /* wait for space */ } distance = 0; obstacle_visible = 0; player_pos_y = PLAYER_POS_Y; player_speed_y = 0; player_jump_remaining = 0; frame_count = 0; } napms(frame_period); } } int main(int argc, char *argv[]) { init(); draw_title(); wrefresh(win); while (getch() != ' ') { /* wait for space */ } game_loop(); cleanup(); return 0; } ``` 这个代码是一个使用 curses 库的 Moon-Buggy 游戏。游戏中,玩家需要控制一辆月球车,躲避障碍物并尽可能地前进,直到撞上障碍物或按下 Q 键退出游戏。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值