Coursera's Algorithmic toolbox assignment solutions( Collecting Signatures, Maximum Number of Prizes, Maximum Salary) :

Problem 5: Collecting Signatures

Solution: (in c++)


( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder)


Still working on this problem...
 

 

 

 

 

Problem 6: Maximum Number of Prizes

Solution: (in c++)


( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder)

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i,d;
    cin>>n;
    if(n==1)
{
cout<<"1"<<endl<<"1";
}
else
{
d=n;
vector<long long>v;
for(i=1;i<n;i++)
{
if(d>2*i)
{
v.push_back(i);
d-=i;
}
else
{
v.push_back(d);
break;
}
}
cout<<v.size()<<endl;
for(i=0;i<v.size();i++)
{
cout<<v[i]<<" ";
}
}
}

Stay tuned for the explanation!!!
 

 

 

 

Problem 7: Maximum Salary

Solution: (in c++)


( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder)

#include<bits/stdc++.h>
using namespace std;
int compare(string x,string y)
{
string xy=x.append(y);
string yx=y.append(x);
return xy.compare(yx)>0? 1:0;
}
void printlargest(vector<string> arr)
{
sort(arr.begin(),arr.end(),compare);
for (int i=0;i<arr.size();i++)
{
cout << arr[i];
}
}
int main()
{
int n,i;
string p;
cin>>n;
vector<string>v;
for(i=0;i<n;i++)
{
cin>>p;
v.push_back(p);
}
printlargest(v);
}

Stay tuned for the explanation!!!
 

 

 

Guys , if you have any queries related to a question or need more explanation, comment down below! 

Comments

Popular posts from this blog

Coursera's Algorithmic toolbox assignment solutions( Sum of Two Digits, Maximum Pairwise Product ) :

HackerEarth's basic programming solutions( Seating Arrangement, Zoos, Anagrams ) :

HackerEarth's basic programming solutions( Minimize Cost, Magical Word, Best Index ) :