String Zig Zag Pattern
Given a string S and an integer N as the input, the program must split the string into groups whose size is N and print them as the output in separate lines in a zig zag manner. If the last group size is less than N then the remaining letters must be filled with asterisk as shown in the Example Input/Output.
Input Format:
The first line contains S.
The second line contains N.
The first line contains S.
The second line contains N.
Output Format:
LENGTH(S)/N + LENGTH(S)%N lines containing the desired pattern.
LENGTH(S)/N + LENGTH(S)%N lines containing the desired pattern.
Boundary Conditions:
4 <= LENGTH(S) <= 500
2 <= N <= LENGTH(S)
4 <= LENGTH(S) <= 500
2 <= N <= LENGTH(S)
Example Input/Output 1:
Input:
ENVIRONMENT
3
Input:
ENVIRONMENT
3
Output:
ENV
ORI
NME
*TN
ENV
ORI
NME
*TN
Example Input/Output 2:
Input:
ENVIRONMENT
4
Input:
ENVIRONMENT
4
Output:
ENVI
MNOR
ENT*
ENVI
MNOR
ENT*
Example Input/Output 3:
Input:
EVERYDAY
2
Input:
EVERYDAY
2
Output:
EV
RE
YD
YA
EV
RE
YD
YA
C++program:
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
string s;
int n,c=0,l;
cin>>s;
cin>>n;
l=s.length();
while(l%n!=0)
{
s.append("*");
l=s.length();
}
int i=0,t=0;
while(i<l)
{
cout<<s[i];
c++;
if(c==n)
{
c=0;
cout<<"\n";
i=i+n;
t++;
}
else
{
if(t%2==0)
i++;
else
i--;
}
}
}
gud job!!
ReplyDelete
ReplyDeleteThanks for providing good information,Thanks for your sharing python Online Course
thanks
ReplyDeleteIt's not passing
ReplyDeleteRespect and that i have a super supply: How To House Renovation complete home renovation
ReplyDelete