标签:
Given any string of N (>=5) characters, you are asked to form the characters into the shape of U. For example, "helloworld" can be printed as:
h d
e l
l r
lowo
1 #include<stdio.h> 2 #include<iostream> 3 #include<string.h> 4 using namespace std; 5 const int MAXN = 100; 6 char s[MAXN]; 7 int main(){ 8 while(~scanf("%s",s)){ 9 int k; 10 int i=0; 11 int lgt=0; 12 while(s[i++]!=‘\0‘); 13 lgt=i-1; 14 if(lgt%3==0){ 15 k=lgt/3; 16 } 17 else{ 18 k=lgt/3+1; 19 } 20 int gap=lgt-k*2; 21 int st=0;int ed=lgt-1; 22 for(i=0;i<k-1;i++){ 23 printf("%c",s[st++]); 24 for(int j=0;j<gap;j++) 25 printf(" "); 26 printf("%c\n",s[ed--]); 27 } 28 while(st<=ed) 29 printf("%c",s[st++]); 30 printf("\n"); 31 } 32 } 33 34 /************************************************************** 35 Problem: 1464 36 User: blueprintf 37 Language: C++ 38 Result: Accepted 39 Time:10 ms 40 Memory:1520 kb 41 ****************************************************************/
标签:
原文地址:http://www.cnblogs.com/blueprintf/p/5618902.html