안녕하세요. 오늘은 바이오리듬을 알아볼 거예요.
https://www.acmicpc.net/problem/23292
biorhythm 함수를 만들어서 두 수의 바이오리듬값을 구해봅시다.
그리고 이 값의 최댓값을 구하면 되는데 값이 같다면 날짜가 작은 순서대로, 즉 값이 작은 순서대로 확인해주면 됩니다.
#include <iostream>
#define ll long long
using namespace std;
ll biorhythm(ll birthday, ll now)
{
ll ans = 1, temp;
temp = 0;
temp += (birthday % 10 - now % 10) * (birthday % 10 - now % 10);
birthday /= 10; now /= 10;
temp += (birthday % 10 - now % 10) * (birthday % 10 - now % 10);
birthday /= 10; now /= 10;
ans *= temp;
temp = 0;
temp += (birthday % 10 - now % 10) * (birthday % 10 - now % 10);
birthday /= 10; now /= 10;
temp += (birthday % 10 - now % 10) * (birthday % 10 - now % 10);
birthday /= 10; now /= 10;
ans *= temp;
temp = 0;
temp += (birthday % 10 - now % 10) * (birthday % 10 - now % 10);
birthday /= 10; now /= 10;
temp += (birthday % 10 - now % 10) * (birthday % 10 - now % 10);
birthday /= 10; now /= 10;
temp += (birthday % 10 - now % 10) * (birthday % 10 - now % 10);
birthday /= 10; now /= 10;
temp += (birthday % 10 - now % 10) * (birthday % 10 - now % 10);
birthday /= 10; now /= 10;
ans *= temp;
return ans;
}
int main(void)
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
ll birthday, N, i, now, mx = -1, date = 2e9;
cin >> birthday >> N;
for (i = 0; i < N; i++)
{
cin >> now;
ll num = biorhythm(birthday, now);
if (mx < num)
{
mx = num;
date = now;
}
if (mx == num)
{
if (now < date)
{
date = now;
}
}
}
cout << date;
}
감사합니다.