// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
int GetUglyNumber_Solution(int index) {
int Max = 0;//记录最大丑数
int num = 0;
vector<int> vec;
int i = 1;
if (index == 0)//如果index是0,返回0
return 0;
while (i <= index)
{
if (i == 1)
vec.push_back(i);
else
{
int num1 = searchNum(vec, 2);
int num2 = searchNum(vec, 3);
int num3 = searchNum(vec, 5);
int min = minNum(num1, num2, num3);
vec.push_back(min);
}
i++;
}
Max = *(vec.end() - 1);
return Max;
}
int searchNum(vector<int> vec, int multiplier)//数组里面的数都乘以一个数之后,返回第一个大于vec数组里面的那个数
{
vector<int> copyVec;
int finanlNum = *(vec.end() - 1);
int flag = 0;
for (auto it = vec.begin(); it < vec.end(); it++)
{
copyVec.push_back((*it)*multiplier);
}
for (auto it = copyVec.begin(); it < copyVec.end(); it++)
{
if (*it > finanlNum)
{
flag = *it;
break;
}
}
return flag;
}
int minNum(int num1, int num2, int num3)//返回三个数字里面的最小值
{
int min = num1 < num2 ? num1 : num2;
min = min < num3 ? min : num3;
// cout << "min:" << min << endl;
return min;
}
};
int main()
{
int num;
Solution so;
// num = so.GetUglyNumber_Solution(1);
while (cin >> num)
{
cout << "第" << num <<"个数是:"<< so.GetUglyNumber_Solution(num) <<endl;
}
vector<int> a;
return 0;
}