Problem link-Click here
in this problem i faced the problem of when to stop taking input but after a while i realize that i have to take input until end of file and also have to stop taking input pressing Ctrl+z button. so do that.
an accepted code is as follows:
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str[105];
int p=0,best_len=0;
while(getline(cin,str[p]))
{
if(str[p].length()>best_len)
{
best_len = str[p].length();
}
p++;
}
for(int i=0;i<best_len;i++)
{
for(int j=p-1;j>=0;j--)
{
if(str[j].length()>i)
{
cout<<str[j][i];
}
else
{
cout<<" ";
}
}
cout<<endl;
}
}
in this problem i faced the problem of when to stop taking input but after a while i realize that i have to take input until end of file and also have to stop taking input pressing Ctrl+z button. so do that.
an accepted code is as follows:
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str[105];
int p=0,best_len=0;
while(getline(cin,str[p]))
{
if(str[p].length()>best_len)
{
best_len = str[p].length();
}
p++;
}
for(int i=0;i<best_len;i++)
{
for(int j=p-1;j>=0;j--)
{
if(str[j].length()>i)
{
cout<<str[j][i];
}
else
{
cout<<" ";
}
}
cout<<endl;
}
}
No comments:
Post a Comment