nefuoj-1041:字符串变形记
2016-02-12 16:22
323 查看
description |
<span style="font-family:SimSun;font-size:18px;">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. </span> |
input |
<span style="font-family:SimSun;font-size:18px;">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. </span> |
output |
<span style="font-family:SimSun;font-size:18px;">For each case, print the circumgrated string.</span> |
sample_input |
<span style="font-family:SimSun;font-size:18px;">asdfass 7</span> |
sample_output |
<span style="font-family:SimSun;font-size:18px;">a s d f a s s</span> |
code:
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int main()
{
char s[105];
int n;
while(cin>>s)
{
cin>>n;
n%=8;
int len=strlen(s);
if(n==0)
{
puts(s);
continue;
}
if(n==7)
{
for(int i=0; i<len; i++)
{
for(int j=0; j<i; j++)
putchar(' ');
printf("%c\n",s[i]);
}
continue;
}
if(n==6)
{
for(int i=0; i<len; i++)
{
printf("%c\n",s[i]);
}
continue;
}
if(n==5)
{
for(int i=len-1; i>=0; i--)
{
for(int j=0; j<i; j++)
putchar(' ');
printf("%c\n",s[len-i-1]);
}
continue;
}
if(n==4)
{
for(int i=len-1; i>=0; i--)
putchar(s[i]);
putchar('\n');
continue;
}
if(n==3)
{
for(int i=len-1; i>=0; i--)
{
for(int j=0; j<len-i-1; j++)
putchar(' ');
printf("%c\n",s[i]);
}
continue;
}
if(n==2)
{
for(int i=len-1; i>=0; i--)
{
printf("%c\n",s[i]);
}
continue;
}
if(n==1)
{
for(int i=len-1; i>=0; i--)
{
for(int j=0; j<i; j++)
putchar(' ');
printf("%c\n",s[i]);
}
continue;
}
}
return 0;
}
下边的code是学校给的答案,说起来用switch语句看起来的确会舒服一点,但是字符数并没有少多少,,。,,
code2:
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
char str[100];
int n,i,j;
while(scanf("%s%d",str,&n)!=-1)
{
if(n>=0) n%=8;
else
{
n%=8;n+=8;n%=8;
}
int len=strlen(str);
switch(n)
{
case 0:
printf("%s\n",str);
break;
case 1:
for(i=len-1;i>=0;i--)
for(j=0;j<=i;j++)
if(j==i) printf("%c\n",str[i]);
else printf(" ");
break;
case 2:
for(i=len-1;i>=0;i--)
for(j=0;j<=len/2;j++)
if(j==len/2) printf("%c\n",str[i]);
else printf(" ");
break;
case 3:
for(i=len-1;i>=0;i--)
for(j=0;j<=len-1-i;j++)
if(j==len-1-i) printf("%c\n",str[i]);
else printf(" ");
break;
case 4:
for(i=len-1;i>=0;i--)
printf("%c",str[i]);
printf("\n");
break;
case 5:
for(i=0;i<len;i++)
for(j=0;j<=len-1-i;j++)
if(j==len-1-i) printf("%c\n",str[i]);
else printf(" ");
break;
case 6:
for(i=0;i<len;i++)
for(j=0;j<=len/2;j++)
if(j==len/2) printf("%c\n",str[i]);
else printf(" ");
break;
case 7:
for(i=0;i<len;i++)
for(j=0;j<=i;j++)
if(j==i) printf("%c\n",str[i]);
else printf(" ");
break;
}
}
return 0;
}
相关文章推荐
- 关于asp.net三种重定向方法的总结
- 【小作品】STM32无线WIFI视频小车制作剖析(下)
- iOS 【UIKit-转换坐标系(1)】
- App Manifest详解
- ViewPagerIndicator的使用
- 1019. 数字黑洞 (20)
- 图的色数
- Python|函数
- 得到刚刚插入数据库数据的主键ID
- Oracle varchar2 length 分析
- poj2955 区间DP
- 初识前端模板引擎jade
- Android电话拨号器的实现
- java基础15迭代器
- ANDROID_MARS学习笔记_S02_003_AutoCompleteTextView
- C#成神之路<18> C#使用磁盘数据文件(2)
- ANDROID_MARS学习笔记_S02_002_Date\TimePicker
- Windows 安装 JDK 环境变量设置
- Directx下的Effect框架
- 1030. Travel Plan (30)