description |
|
input |
|
output |
|
sample_input |
|
sample_output |
|
题解:模拟,纯粹的模拟,而且还得挨个模拟,敲着好累啊。。。
code:
#include <cstring>
#include <cstdio>
using namespace std;
{
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;
}