1440
주어진 수를 parsing하고, 시 분 초를 순열로 돌려서 만족하는 조합을 찾는 문제
예
내 방법
- 삼중 반복문을 각각 0부터 순차적으로 돌린다
- 만약 각각의 인덱스가 서로 다를 때만 체크한다.
- 012
- 021
- 102
- 120
- 201
- 210
- 순으로 아마 반복문이 돌것이다.
- 첫 번째 인덱스로 준건 무조건 "시"라고 생각하고 조건을 걸고,
- 나머지 두 개는 "분 또는 초"로 0~ 59까지 들어가는 지 확인을 해주면 된다.
- 어떤게 시가 되든지 상관없으므로, 계산의 편의를 위해 첫 번째로 온놈을 시라고 생각했다.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int solution(vector<string> strs)
{
int count = 0;
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
for (int k = 0; k < 3; k++)
{
if (i != j && j != k && k != i)
{
if ((stoi(strs[i]) >= 1 && stoi(strs[i]) <= 12) &&
stoi(strs[j]) >= 0 && stoi(strs[j]) <= 59 &&
stoi(strs[k]) >= 0 && stoi(strs[k]) <= 59)
count++;
}
}
return count;
}
int main(void)
{
string input;
vector<string> strs;
cin >> input;
strs.push_back(input.substr( 0, 2));
strs.push_back(input.substr( 3, 2));
strs.push_back(input.substr( 6, 2));
cout << solution(strs) << endl;
}