-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombination-largest-integer.cpp
More file actions
60 lines (52 loc) · 1.28 KB
/
Copy pathcombination-largest-integer.cpp
File metadata and controls
60 lines (52 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <vector>
#include <string>
#include <stdexcept>
#include <algorithm>
#include <sstream>
#include <boost/lexical_cast.hpp>
int converting_vectorint_to_int(const std::vector<int>& v)
{
}
void print_vector (const std::vector<int>& v)
{
for(unsigned int i = 0; i < v.size();++i)
{
std::cout << v[i];;
}
std::cout << '\n';
}
//using a vector of integers find the combiniantion that grants the largest integer by concatenating
//all integers in the vector
int find_largest_int_concat(std::vector<int> numbers)
{
std::stringstream ss;
std::string perm;
//auto find_first_digit = [](int number) ->int {while(number>=10) number/=10;return number;};
//std::sort (numbers.begin(),numbers.end());
do
{
for(int i: numbers)
{
ss << i;
}
if(ss.str() > perm)
{
perm = ss.str();
}
ss.str("");
//print_vector(numbers);
}
while(std::next_permutation(numbers.begin(),numbers.end()));
std::cout << "perm: " << perm << '\n';
return 1;
}
int main()
{
std::vector<int> numbers = {54,546,548,60};
std::vector<int> numbers2 = {1, 34, 3, 98, 9, 76, 45, 4}
;
//converting_vectorint_to_int(numbers);
std::cout << find_largest_int_concat(numbers) << '\n';
std::cout << find_largest_int_concat(numbers2) << '\n';
}