#include <stdio.h>
#include <windows.h>
#include <string.h>
#include <conio.h>
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
int l = 43;
int u = 0;
int d = 44;
int s = 0;
int x = 59;
int y = 0; //플레이어의 위치
int a =60;
int b=0;
int g=0;
int timeminute=0;
int timesecond=0;
int timesecondminus=0;
enum {
BLACK,
DARK_BLUE,
DARK_GREEN,
DARK_SKYBLUE,
DARK_RED,
DARK_VOILET,
DAKR_YELLOW,
GRAY,
DARK_GRAY,
BLUE,
GREEN,
SKYBLUE,
RED,
VIOLET,
YELLOW,
WHITE,
};
void setColor(unsigned short text) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), text);
}
void gotoxy(int y, int x);
void info();
int f=0,score=0,life=3,jumps=0, j=0,p=0,max=0,i=0;
int main()
{
system("mode con:cols=80 lines=25");
char c;
info();
gotoxy(19, 0);
setColor(GREEN);
printf("/");
gotoxy(18, 1);
setColor(GREEN);
printf("/");
gotoxy(17, 2);
setColor(GREEN);
printf("/");
gotoxy(16, 3);
setColor(GREEN);
printf("/");
gotoxy(16, 4);
setColor(GREEN);
printf("\\");
gotoxy(17, 5);
setColor(GREEN);
printf("\\");
gotoxy(18, 6);
setColor(GREEN);
printf("\\");
gotoxy(19, 7);
setColor(GREEN);
printf("\\");
gotoxy(17, 6);
setColor(GREEN);
printf("/");
gotoxy(16, 7);
setColor(GREEN);
printf("/");
gotoxy(15, 8);
setColor(GREEN);
printf("/");
gotoxy(14,9);
setColor(GREEN);
printf("/");
gotoxy(13,10);
setColor(GREEN);
printf("/");
gotoxy(19, 17);
setColor(GREEN);
printf("\\");
gotoxy(18, 16);
setColor(GREEN);
printf("\\");
gotoxy(17, 15);
setColor(GREEN);
printf("\\");
gotoxy(16, 14);
setColor(GREEN);
printf("\\");
gotoxy(15, 13);
setColor(GREEN);
printf("\\");
gotoxy(14 ,12);
setColor(GREEN);
printf("\\");
gotoxy(13,11);
setColor(GREEN);
printf("\\");
gotoxy(14, 30);
setColor(GREEN);
printf(" \\ /");
gotoxy(15, 30);
setColor(GREEN);
printf("- O -");
gotoxy(16, 30);
setColor(GREEN);
printf(" / \\");
gotoxy(20, 0);
setColor(GREEN);
printf("--------------------------------------------");
gotoxy(20, 5);
setColor(RED);
printf("^");
gotoxy(19, 5);
setColor(BLUE);
printf("T");
gotoxy(18, 5);
setColor(YELLOW);
printf("O");
for (;;)
{
gotoxy(15+5, 5);
setColor(RED);
printf("^");
gotoxy(15, 30);
printf("- O -");
gotoxy(16, 30);
printf(" / \\");
obstacle(score);
f=0;
gotoxy(4,4);
printf("O-------------------------O");
gotoxy(5,4);
printf("| |");
gotoxy(6,4);
printf("| |");
gotoxy(7,4);
printf("| |");
gotoxy(5,5);
printf("LIFE : %d",life);
gotoxy(6,5);
printf("SCORE : %d",score);
gotoxy(7,5);
printf("NUMBER OF JUMPS : %d",g);
gotoxy(8,4);
printf("O-------------------------O");
if (_kbhit()) {
c = _getch();
f=f+1;
g=g+1;
gotoxy(20,5);
printf(" ");
gotoxy(19,5);
printf(" ");
gotoxy(18,5);
printf(" ");
gotoxy(20-1, 5);
setColor(RED);
printf("V");
gotoxy(19-1, 5);
setColor(BLUE);
printf("Y");
gotoxy(18-1, 5);
setColor(YELLOW);
printf("O");
f=f+1;
if(j==0)
{
gotoxy(19, 5);
setColor(RED);
printf("^");
gotoxy(18, 5);
setColor(BLUE);
printf("T");
gotoxy(17, 5);
setColor(YELLOW);
printf("O");
Sleep(10);
obstacle();
gotoxy(19,5);
printf(" ");
gotoxy(18,5);
printf(" ");
gotoxy(17,5);
printf(" ");
gotoxy(18, 5);
setColor(RED);
printf("^");
gotoxy(17, 5);
setColor(BLUE);
printf("T");
gotoxy(16, 5);
setColor(YELLOW);
printf("O");
Sleep(10);
obstacle();
gotoxy(18,5);
printf(" ");
gotoxy(17,5);
printf(" ");
gotoxy(16,5);
printf(" ");
gotoxy(17, 5);
setColor(RED);
printf("^");
gotoxy(16, 5);
setColor(BLUE);
printf("Y");
gotoxy(15, 5);
setColor(YELLOW);
printf("O");
Sleep(10);
obstacle();
gotoxy(17,5);
printf(" ");
gotoxy(16,5);
printf(" ");
gotoxy(15,5);
printf(" ");
gotoxy(16, 5);
setColor(RED);
printf("V");
gotoxy(20,x--);
printf("M");
Sleep(10);
score=score+1;
gotoxy(20,a--);
setColor(GREEN);
printf("-");
Sleep(10);
if(x==0)
{
x=x+59;
}
gotoxy(15, 5);
printf("Y");
setColor(BLUE);
gotoxy(14, 5);
setColor(YELLOW);
printf("O");
Sleep(10);
obstacle();
gotoxy(16,5);
printf(" ");
gotoxy(15,5);
printf(" ");
gotoxy(14,5);
printf(" ");
gotoxy(16, 5);
setColor(RED);
printf("V");
gotoxy(15, 5);
setColor(BLUE);
printf("Y");
gotoxy(14, 5);
setColor(YELLOW);
printf("O");
Sleep(10);
obstacle();
gotoxy(16,5);
printf(" ");
gotoxy(15,5);
printf(" ");
gotoxy(14,5);
printf(" ");
gotoxy(16, 5);
setColor(RED);
printf("V");
gotoxy(15, 5);
setColor(BLUE);
printf("Y");
gotoxy(14, 5);
setColor(YELLOW);
printf("O");
Sleep(10);
obstacle();
gotoxy(16,5);
printf(" ");
gotoxy(15,5);
printf(" ");
gotoxy(14,5);
printf(" ");
gotoxy(17, 5);
setColor(RED);
printf("^");
gotoxy(16, 5);
setColor(BLUE);
printf("Y");
gotoxy(15, 5);
setColor(YELLOW);
printf("O");
Sleep(10);
obstacle();
gotoxy(17,5);
printf(" ");
gotoxy(16,5);
printf(" ");
gotoxy(15,5);
printf(" ");
gotoxy(18, 5);
setColor(RED);
printf("^");
gotoxy(17, 5);
setColor(BLUE);
printf("T");
gotoxy(16, 5);
setColor(YELLOW);
printf("O");
Sleep(10);
obstacle();
gotoxy(18,5);
printf(" ");
gotoxy(17,5);
printf(" ");
gotoxy(16,5);
printf(" ");
gotoxy(19, 5);
setColor(RED);
printf("^");
gotoxy(18, 5);
setColor(BLUE);
printf("T");
gotoxy(17, 5);
setColor(YELLOW);
printf("O");
Sleep(10);
obstacle();
gotoxy(19,5);
printf(" ");
gotoxy(18,5);
printf(" ");
gotoxy(17,5);
printf(" ");
gotoxy(20, 5);
setColor(RED);
printf("V");
gotoxy(19, 5);
setColor(BLUE);
printf("Y");
gotoxy(18, 5);
setColor(YELLOW);
printf("O");
Sleep(10);
gotoxy(20,5);
printf(" ");
gotoxy(19,5);
printf(" ");
gotoxy(18,5);
printf(" ");
}
else if(j==1)
{
Sleep(2);
obstacle();
Sleep(2);
obstacle();
Sleep(2);
obstacle();
Sleep(2);
obstacle();
Sleep(2);
obstacle();
Sleep(2);
obstacle();
Sleep(2);
obstacle();
}
else
{
Sleep(1);
obstacle();
Sleep(1);
obstacle();
Sleep(1);
obstacle();
Sleep(1);
obstacle();
Sleep(1);
obstacle();
Sleep(1);
obstacle();
Sleep(1);
obstacle();
}
gotoxy(15,5);
printf(" ");
gotoxy(14,5);
printf(" ");
gotoxy(13,5);
printf(" ");
gotoxy(15+5, 5);
setColor(RED);
printf("^");
gotoxy(14+5, 5);
setColor(BLUE);
printf("T");
gotoxy(13+5, 5);
setColor(YELLOW);
printf("O");
}
if(f==0&&x==4)
{
life=life-1;
gotoxy(16,20);
setColor(RED);
printf("CRASH!!(충돌!!)");
Sleep(1000);
gotoxy(16,20);
printf(" ");
g=0;
}
else if(x==2&&g!=0)
{
gotoxy(16,20);
g=0;
score=score+101;
}
else if(life<=0)
{
gotoxy(15,20);
setColor(RED);
printf("*(((||FAIL||)))*");
Sleep(4000);
gotoxy(15,20);
printf(" ");
score=0;
life=3;
}
else
{
score=score+1;
}
if(score==1000||score==2000||score==3000||score==4000||score==5000||score==6000||score==7000||score==8000||score==9000||score==11000||score==12000||score==13000||score==14000||score==15000)
{
life+=1;
}
else if(score==10000)
{
life+=5;
}
}
}
//20,59
void gotoxy(int y, int x) {
COORD Pos;
Pos.X = x; Pos.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}
void info()
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
gotoxy(10, 20);
printf("**GAME RULE**(게임 규칙)\n");
gotoxy(11, 20);
printf("Jump by pressing any key(아무키나 누르면 점프가 됩니다)\n");
gotoxy(12, 20);
printf("Avoid obstacle M.(M을 피하세요.)\n");
}
void obstacle()
{
gotoxy(20,x--);
printf("M");
Sleep(10);
timesecondminus+=1;
gotoxy(20,a--);
setColor(GREEN);
printf("-");
Sleep(10);
if(x==0)
{
x=x+59;
}
}
#include <stdio.h>
int queue[1001]={0};
int front=-1;
int rear=-1;
void enqueue(int data)
{
rear++;
queue[rear]=data;
}
int dequeue()
{
front++;
return queue[front];
}
int main()
{
int a,b,i,n;
printf("Queue 프로그램입니다\n\n");
while(1)
{
printf("1.enqueue 2. dequeue 3. view >>");
scanf("%d",&a);
if(a==1){
printf("enqueue할 데이터를 적으세요 >> ");
scanf("%d",&b);
enqueue(b);
}
else if(a==2){
if(front==rear){
//큐 비어있다고 출력
printf("queue가 비어 있습니다.\n");
}
else
{
//deq한 데이터 출력
printf("dequeue한 데이터는 %d 입니다.\n'",dequeue());
}
}
else if(a==3)
{
if(front==rear){
printf("queue가 비어있습니다.\n");
}
else
{
printf("queue [ ");
for (int i=front+1 ; i<=rear;i++)
{
printf("%d ",queue[i]);
}
printf("]\n");
}
}
}
return 0;
}
메모이제이션
arr[i] : i번째 입력된 데이터 (x)
arr[i] : i에 대한 정보 ( i가 입력된 횟수 )
1093번 참고
*/
#include<stdio.h>
int main()
{
int a,t=0,i=0,j=0,arr[100001]={};
scanf("%d",&a);
for(i=1;i<=a;i++)
{
scanf("%d",&t);
arr[t]++;
}
//i를 arr[i]번 출력--> for문 2개
for(i=0;i<=100000;i++)
{
for(j=1;j<=arr[i];j++)
{
printf("%d ",i);
}
}
return 0;
}