꼬반 Blog

그리드 실행시간 구하기 포함버젼.



#include <stdio.h>
#include <windows.h>

#define MAX 150
#define CA 500
#define CB 100
#define CC 50
#define CD 10
#define CLK_TCK 1000

int queue1[MAX]; // 잔액
int queue2[MAX]; // 500원
int queue3[MAX]; // 100원
int queue4[MAX]; // 50원
int queue5[MAX]; // 10원

void add2(int x2, int y2);
void add3(int x3, int y3);
void add4(int x4, int y4);
void add5(int x5, int y5);
void del();

void greedy(int c1, int c2);
void makenode();
void print();
void count();

int front1 = 0, rear1 = 0;
int front2 = 0, rear2 = 0;
int front3 = 0, rear3 = 0;
int front4 = 0, rear4 = 0;
int front5 = 0, rear5 = 0;

int cnt = 0;
int tf2, tf3, tf4, tf5;

void main()
{
 long start, stop;
 float time;
 
 int in, in2;
 in = 0;
 in2 = 0;
 
 printf("금액을 넣어주세요 : ");
 scanf("%d",&in);
 printf("\n사용한 금액은 얼마인가요 : ");
 scanf("%d", &in2);
 
 start = GetTickCount();
 greedy(in, in2);
 stop = GetTickCount();
 
 time = (float)(stop-start)/CLK_TCK;
 
 printf("TIME : %f s\n", time);
}

void greedy(int c1, int c2)
{
 int charge = c1 - c2;
 
 queue1[0] = charge;
 printf("잔액 설정 : %d \n",queue1[0]);

 while(1)
 {
  if(cnt == 1)
  {
   count();
   printf("잔액 %d원의 거스름돈 동전의 갯수는 \n500원 : %d개 , 100원 : %d개, 50원 : %d개, 10원 : %d개 입니다.\n", queue1[0], tf2, tf3, tf4, tf5);
   break;
  }
  makenode();
  //print();
  del();
 }
}


void makenode()
{
 int t, t2, t3, t4, t5;
 
 if(queue1[front1] == 0)
 {
  cnt++;
 }
  
 if(queue1[front1] > 0)
 {
  if(queue1[front1] >= CA)
  {
   t = queue1[front1] - CA;
   t2 = 1;
   add2(t, t2);
  }
 
  if(queue1[front1] >= CB)
  {
   t = queue1[front1] - CB;
   t3 = 1;
   add3(t, t3);
  }
 
  if(queue1[front1] >= CC)
  {
   t = queue1[front1] - CC;
   t4 = 1;
   add4(t, t4);
  }
 
  if(queue1[front1] >= CD)
  {
   t = queue1[front1] - CD;
   t5 = 1;
   add5(t, t5);
  }
 }
}

void add2(int x2, int y2)
{
 if(rear1 == MAX) rear1 = 0;
 queue1[++rear1] = x2;
 if(rear2 == MAX) rear2 = 0;
 if(y2 == 1)
 {
  queue2[rear2] = y2;
 }else queue2[rear2] = 0;
 rear2++;
}

void add3(int x3, int y3)
{
 if(rear1 == MAX) rear1 = 0;
 queue1[++rear1] = x3;
 if(rear3 == MAX) rear3 = 0;
 if(y3 == 1)
 {
  queue3[rear3] = y3;
 }else queue3[rear3] = 0;
 rear3++;
}

void add4(int x4, int y4)

 if(rear1 == MAX) rear1 = 0;
 queue1[++rear1] = x4;
 if(rear4 == MAX) rear4 = 0;
 if(y4 == 1)
 {
  queue4[rear4] = y4;
 }else queue4[rear4] = 0;
 rear4++;
}

void add5(int x5, int y5)
{
 if(rear1 == MAX) rear1 = 0;
 queue1[++rear1] = x5;
 if(rear5 == MAX) rear5 = 0;
 if(y5 == 1)
 {
 queue2[rear5] = y5;
 }else queue5[rear5] = 0;
 rear5++;
}


void del()
{
 if(front1 == MAX) front1 = 0;
 front1++;
}


void print()
{
 printf("잔액 : %d \n",queue1[front1]);
}

void count()
{
 int t[4] = {0, 0, 0, 0};
 int i = 0;
 int cg = queue1[0];

 while(cg > 0)
 {
  if(cg >= CA)
  {
   cg = cg - CA;
   t[0] = t[0]++;
  }
  else if(cg >= CB)
  {
   cg = cg - CB;
   t[1] = t[1]++;
  }else if(cg >= CC)
  {
   cg = cg - CC;
   t[2] = t[2]++;
  }
  else if(cg >= CD)
  {
   cg = cg - CD;
   t[3] = t[3]++;
  }
 }
 tf2 = t[0];
 tf3 = t[1];
 tf4 = t[2];
 tf5 = t[3];
}

반응형

Article By 꼬반

*certificate* : VCP 5(2012), RHCSA 7 (2014), RHCE 7 (2015), RHCSA in REDHAT OpenStack(2017) *development language* : Javascript, NodeJS, Golang, html5, css3, shell script *middle ware* : NGINX, Apache, Tomcat, Docker, Docker Swarm, Mesos, Kubernetes, HCI,

Discuss about post