Here is the code..please help.
Also, please let me know where do i look for the particular error messages taht the online compiler throws..
Thanks.
Code: Select all
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
vector<string> strings;
string temp;
vector<string>::const_iterator iter;
unsigned num=0;
unsigned count=0;
unsigned maxLength = 0;
unsigned cols=0;
unsigned rows=0;
int i=0;
int j=0;
while(cin>>num)
{
getline(cin,temp);//to read the '\n' after the number
maxLength=rows=cols=0;
for(count=0;count<num;++count)
{
getline(cin,temp);
maxLength = max(maxLength, unsigned(temp.length()));
strings.push_back(temp);
}
sort(strings.begin(),strings.end());
//cout<<maxLength<<endl;
//assert(maxLength<=60);
cols=(60-maxLength)/(maxLength+2) + 1;
rows= (num%cols)?(num/cols+1):(num/cols);
i=j=0;
//cout<<maxLength<<"\t"<<rows<<"\t"<<cols;
//draw a line of dashes
while(i++<60)
cout<<'-';
for(i=0;i<rows;i++)
{
cout<<endl;
for(j=0;j<cols;j++)
if((i+j*rows)<num)
cout<<left<<setw(maxLength+2)<<strings[i+j*rows];
}
cout<<endl;
strings.clear();
}
return 0;
}