题目1464:Hello World for U(找规律)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了题目1464:Hello World for U(找规律)相关的知识,希望对你有一定的参考价值。
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 ****************************************************************/
以上是关于题目1464:Hello World for U(找规律)的主要内容,如果未能解决你的问题,请参考以下文章