꼬반 Blog

간단 그리드 알고리즘


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

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

void count(int c, int b);

void main()
{
 long start, stop;
 float time;

 int charge, bcharge;

 printf("금액 설정 : ");
 scanf("%d",&charge);
 printf("사용할 금액은 : ");
 scanf("%d",&bcharge);
 start = GetTickCount();
 count(charge, bcharge);
 stop = GetTickCount();
 
 time = (float)(stop-start)/CLK_TCK;
 
 printf("TIME : %f s\n", time);
}


void count(int c, int b)
{
 int t[4] = {0, 0, 0, 0};
 int i = 0;
 int cg = c - b;
 
 printf("거스름돈은 %d원 입니다.\n",cg);
 
 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]++;
  }
 }
 printf("\n거스름돈 동전의 갯수는\n500원 %d개, 100원 %d개, 50원 %d개, 10원 %d개 입니다.\n",t[0],t[1],t[2],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