码迷,mamicode.com
首页 > 其他好文 > 详细

题目1464:Hello World for U(找规律)

时间:2016-06-27 01:29:07      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:

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(找规律)

标签:

原文地址:http://www.cnblogs.com/blueprintf/p/5618902.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!