The ancient Chinese wrote characters vertically from right to left. In this question, you are asked to write a program to format a piece of text according to the ancient style.
Input format:
The input is given a positive integer N (<100) on the first line, which is the number of characters in each column. The second line gives a non-empty string of length up to 1000, terminated by a carriage return.
Output format:
Types the given string in archaic style, with N characters per column (except the last column may have fewer than N)
Input sample:4 This is a test caseSample output:
asa T st ih and tsi what s
Code:
#include<stdio.h> #include<string.h> char str[1000][1000],s[1010]; intmain() { int i,j,n,m,k,t,l; scanf("%d",&n); getchar(); gets(s); k=strlen(s); m=k/n; if(k%n!=0) { m++; } i=0; for(j=m-1;j>=0;j--) { for(l=0;l<n;l++) { if(s[i]!='\0') { str[l][j]=s[i++]; } else { str[l][j]=' '; } } } for(i=0;i<n;i++) { for(j=0;j<m;j++) { printf("%c",str[i][j]); } printf("\n"); } return 0; }