circumgyrate the string
Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4534 Accepted Submission(s): 1053
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
题目大意:输入一个字符串和旋转次数,输出旋转后的字符串的位置。每一次旋转按照逆时针45度旋转。
思路:格式控制。
一定要注意,字符串的长度是奇数,所以中间那个字符位置时不变的,比如旋转3次后,字符串是一竖列,
但是前边一定要输出空格。还有下边注释注意的,旋转次数可以为负数。
2015,3,3
*************************/
#include<stdio.h>
#include<string.h>
char ch[83];
int main(){
int i,j,k,n,v,t;
while(~scanf("%s %d",ch,&t)){
n=strlen(ch);
k=t%8;//先取余在进行下边循环,因为如果t是负的很大的数,执行循环就会超时
while(k<0)
k+=8;
if(k==7){
for(i=0;i<n;i++){
for(j=0;j<i;j++){
printf(" ");
}
printf("%c\n",ch[i]);
}
}
else if(k==6){
for(i=0;i<n;i++){
for(j=0;j<n/2;j++){
printf(" ");
}
printf("%c\n",ch[i]);
}
}
else if(k==5){
for(i=0;i<n;i++){
for(j=n-1;j>i;j--){
printf(" ");
}
printf("%c\n",ch[i]);
}
}
else if(k==4){
for(i=n-1;i>=0;i--){
printf("%c",ch[i]);
}
printf("\n");
}
else if(k==3){
for(i=0;i<n;i++){
for(j=0;j<i;j++){
printf(" ");
}
printf("%c\n",ch[n-i-1]);
}
}
else if(k==2){
for(i=n-1;i>=0;i--){
for(j=0;j<n/2;j++){
printf(" ");
}
printf("%c\n",ch[i]);
}
}
else if(k==1){
for(i=n-1;i>=0;i--){
for(j=0;j<i;j++){
printf(" ");
}
printf("%c\n",ch[i]);
}
}
else if(k==0){
puts(ch);
}
}
return 0;
}