HDU 2137 circumgyrate the string
2015-08-15 18:55
387 查看
HDU 2137 circumgyrate the string
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
简单的字符串处理问题,但是有几个注意点:
1、输入有可能是负数
2、当输入是2或6时,注意前面的空格,要不然会PE的
一共八种情况,一一个一个的写就行了,比较麻烦
代码如下:
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
简单的字符串处理问题,但是有几个注意点:
1、输入有可能是负数
2、当输入是2或6时,注意前面的空格,要不然会PE的
一共八种情况,一一个一个的写就行了,比较麻烦
代码如下:
[code]#include<iostream> #include <cstdio> #include <string.h> using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("1.txt","r",stdin); #endif char a[85]; int n, len, i, j; while(~scanf("%s%d", a, &n)) { while (n < 0) { n += 8; } if (n >= 8) { n %= 8; } len = strlen(a); if (n == 0) { cout << a << endl; } else if (n == 1) { for (i = len - 1; i >= 0; i--) { for(j = 1; j <= i; j++) { printf(" "); } cout << a[i] << endl; } } else if (n == 2) { for (i = len - 1; i >= 0; i--) { for (j = 0; j < len/2; j++) cout << " "; printf("%c\n", a[i]); } } else if (n == 3) { for (i = len - 1; i >= 0; i--) { for (j = 1; j < len - i; j++) { printf(" "); } cout << a[i]; cout << endl; } } else if (n == 4) { for (i = len - 1; i >= 0; i--) { cout << a[i]; } cout << endl; } else if (n == 5) { for (i = 0; i < len; i++) { for(j = 1; j < len - i; j++ ) { printf(" "); } cout << a[i] << endl; } } else if (n == 6) { for (i = 0; i < len ; i++) { for(j = 1; j <= len/2; j++) { printf(" "); } printf("%c\n", a[i]); } } else if (n == 7) { for(i = 0; i < len; i++) { for(j = 0; j < i; j++) { cout << " "; } cout << a[i] << endl; } } // cout << endl << endl; } return 0; }
相关文章推荐
- GDOI2016模拟8.14电话表
- uvalive 6122 最长不降子序列
- C# RGB和HSB相互转换
- [Leetcode] Best Time to Buy and Sell Stock I,II,III,IV
- poj 3692 二分图最大独立集
- 黑马程序员——java基础_正则表达式
- stl map 插入方式和特别需要注意的区别
- hdu 5389 Zero Escape (DP+类似01背包)
- java 排错的技巧
- linux cp命令批量复制不提示方法
- 树莓派用Python写几个简单程序6_yeelink平台
- HDU149850 years, 50 colors(行列匹配+最小点覆盖)
- 关于NSArray使用时用strong修饰还是copy修饰问题测试
- C语言中函数参数入栈的顺序 - Fangzhen - 博客园
- hdu5385(2015多校8)--The path(贪心,搜索)
- ZigZag Conversion
- UITableView2 - 复用的理解和cell的创建
- hdu 1514 树状数组模板题
- 在界面条件检索时设置默认时间
- [Leetcode] Populating Next Right Pointers in Each Node I,II