Problem link-Click here
One of the string processing problem. try to figure out the pattern behind this problem.
accepted code is as follows:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
cin.ignore();
while(t--)
{
string str;
getline(cin,str);
double m=sqrt(str.length());
int m1=sqrt(str.length());
if(m==m1)
{
for(int i=0;i<m1;i++)
{
for(int j=i;j<str.length();j=j+m1)
{
cout<<str[j];
}
}
cout<<endl;
}
else
{
cout<<"INVALID"<<endl;
}
}
return 0;
}
One of the string processing problem. try to figure out the pattern behind this problem.
accepted code is as follows:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
cin.ignore();
while(t--)
{
string str;
getline(cin,str);
double m=sqrt(str.length());
int m1=sqrt(str.length());
if(m==m1)
{
for(int i=0;i<m1;i++)
{
for(int j=i;j<str.length();j=j+m1)
{
cout<<str[j];
}
}
cout<<endl;
}
else
{
cout<<"INVALID"<<endl;
}
}
return 0;
}
No comments:
Post a Comment