Skip to content

Instantly share code, notes, and snippets.

@mehmetaltuner
Created November 30, 2018 17:26
Show Gist options
  • Save mehmetaltuner/6791d10d93a90a250ffa75a8db2f9ffe to your computer and use it in GitHub Desktop.
Save mehmetaltuner/6791d10d93a90a250ffa75a8db2f9ffe to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
string ltrim(const string &);
string rtrim(const string &);
void print(int c, int n){
while(n--)
printf("%d", c);
return;
}
// Complete the decentNumber function below.
void decentNumber(int n) {
if(n >= 3){
if(n % 3 == 0){
print(5, n);
return;
}else{
int counter = 0;
int holder = n;
while(n > 3){
n -= 5;
counter++;
if(n % 3 == 0){
print(5, n);
print(3, counter*5);
return;
}
}
if(holder % 5 == 0){
print(3, holder);
return;
}else{
print(-1, 1);
return;
}
}
}else if(n < 3){
print(-1, 1);
return;
}
return;
}
int main()
{
string t_temp;
getline(cin, t_temp);
int t = stoi(ltrim(rtrim(t_temp)));
for (int t_itr = 0; t_itr < t; t_itr++) {
string n_temp;
getline(cin, n_temp);
int n = stoi(ltrim(rtrim(n_temp)));
decentNumber(n);
printf("\n");
}
return 0;
}
string ltrim(const string &str) {
string s(str);
s.erase(
s.begin(),
find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace)))
);
return s;
}
string rtrim(const string &str) {
string s(str);
s.erase(
find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(),
s.end()
);
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment