400. To and Fro Problem code: TOANDFRO
#include<iostream>
using namespace std;
int main()
{
int columns,n,m;
while (1)
{
cin>>columns;
if (columns==0)
break;
string s;
cin >> s;
string r(s);
int rows = s.size() / columns;
for (int i=0; i<s.size(); i++)
{
m = i/columns;
m%2==0?n=i%columns:n = columns-1-i%columns;
r[n*rows+m] = s[i];
}
cout << r << endl;
}
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int columns,n,m;
while (1)
{
cin>>columns;
if (columns==0)
break;
string s;
cin >> s;
string r(s);
int rows = s.size() / columns;
for (int i=0; i<s.size(); i++)
{
m = i/columns;
m%2==0?n=i%columns:n = columns-1-i%columns;
r[n*rows+m] = s[i];
}
cout << r << endl;
}
return 0;
}
No comments:
Post a Comment