Demo entry 6761416

생일자 공격

   

Submitted by 정시윤 on Sep 27, 2018 at 05:42
Language: C++. Code size: 1.7 kB.

#include <iostream>
#include <cstdlib>
#include <Windows.h>

#define defaultcol 7
#define lightblue 9
#define lightgreen 10
#define lightcyan 11
#define red 12

using namespace std;

int overlap(const int day[], int * cntclipptr) {
	
	/* to do
		중복되는 수 있는지 검사하는 함수 제작 */
	
	int i;

	for (i = 0; i < *cntclipptr; i++) {

		int dayarrnum = day[i];

		if ( == )
	}
}

void print(int day) {

	int mday = day, mth = 0;
	int arr[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

	for (mth = 0; mday > arr[mth]; mth = (mth + 1) % 12)
	{
		
		mday -= arr[mth];
	}
	
	cout << mth + 1 << "월 " << mday << "일" << endl;
}

void color(int col) {

	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), col);
}

int main(int argc, char const *argv[]) {

	int cnt;
	int cntclip = cnt;

	color(red);
	cout << "[[[ 생일문제 난수 생성기 ]]]" << endl << endl;

	while (1) {

		color(lightcyan);

		cout << "몇명이 있나요?" << endl << endl;

		color(lightcyan);
		cin >> cnt;

		if (cnt == 0) {

			color(red);

			cout << endl << "프로그램 종료." << endl;

			color(defaultcol);

			return 0;
		}

		else if (cnt > 366) {

			color(red);

			cout << endl << "너무 큰 수 입니다." << endl;
		}

		else {

			color(lightblue);
			cout << endl << cnt << "개의 난수 생성..." << endl << endl;

			for (cnt; cnt > 0; cnt--) {

				/*to do
					overlap 함수로 가는 매개변수 만들기*/

				int i;
				int dayarr[365];
				const int arrnum = cntclip - cnt;

				i = rand() % 365;

				color(lightgreen);

				dayarr[arrnum] = i;
				
				overlap(dayarr, &cntclip);
				print(i);
			}
		}
		
		color(defaultcol);

		cout << endl << endl;
	}
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).