首页 > 代码库 > HDU2137 circumgyrate the string
HDU2137 circumgyrate the string
circumgyrate the string
Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4235 Accepted Submission(s): 978
Problem Description
Give you a string, just circumgyrate. The number N means you just circumgyrate the string N times, and each time you circumgyrate the string for 45 degree anticlockwise.
Input
In each case there is string and a integer N. And the length of the string is always odd, so the center of the string will not be changed, and the string is always horizontal at the beginning. The length of the string will not exceed 80, so we can see the complete result on the screen.
Output
For each case, print the circumgrated string.
Sample Input
asdfass 7
Sample Output
a s d f a s s
Author
wangye
Source
HDU 2007-11 Programming Contest_WarmUp
#include <stdio.h> #include <string.h> #define maxn 100 char str[maxn]; void putBackspace(int n) { while(n--) putchar(' '); } void rotate(int cent, int n) { switch(n) { case 0: puts(str); return; case 1: for(int i = cent << 1, j = cent << 1; i >= 0; --j) { putBackspace(i--); printf("%c\n", str[j]); } return; case 2: for(int j = cent << 1; j >= 0; --j) { putBackspace(cent); printf("%c\n", str[j]); } return; case 3: for(int j = cent << 1, i = 0; j >= 0; --j) { putBackspace(i++); printf("%c\n", str[j]); } return; case 4: for(int j = cent << 1; j >= 0; --j) { printf("%c", str[j]); } putchar('\n'); return; case 5: for(int j = 0, i = cent << 1; i >= 0; ++j) { putBackspace(i--); printf("%c\n", str[j]); } return; case 6: for(int j = 0; j <= cent << 1; ++j) { putBackspace(cent); printf("%c\n", str[j]); } return; case 7: for(int j = 0, i = 0; j <= cent << 1; ++j) { putBackspace(i++); printf("%c\n", str[j]); } return; } } int main() { int n, i, cent; while(scanf("%s%d", str, &n) != EOF) { cent = strlen(str) >> 1; n = (n % 8 + 8) % 8; rotate(cent, n); } return 0; }
HDU2137 circumgyrate the string
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。