此题如果有用JavaACDSee,请评论,谢谢了。

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

题目意思很简单:

输入一个字符串和一个整数n,n表示把字符串逆时针旋转n个45°,输出旋转后的图形。

注意,n可以是负数,如果是负数,就是按照顺时针旋转就可以了。

和HDU2135题类似。那个是矩阵旋转,这个是字符串旋转。

两题做法都一样,找出循环节分别输出。

此题的字符串旋转8次,可以回到原来的位置,所以对8取余,对8种情况分别输出就可以了。

此题有一个问题,我不知道其他人遇到没有,这个题目用JavaAC不了。。。

下面给出WA的Java代码,和AC的C语言代码。—大家可以对比一下。

Java这个代码完全没问题的,至少我还没找到错哪了,如果有找到的,求告知,谢谢。

WA的Java代码:

package cn.hncu.acm;

import java.util.Scanner;

public class P2137 {

    public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String str = sc.next();
int n = sc.nextInt();
n %= 8;
if (n < 0)
n += 8;
int t = str.length();
if (n == 0)
System.out.println(str);
else if (n == 4) {
for (int i = t - 1; i >= 0; i--)
System.out.print(str.charAt(i));
System.out.println();
} else if (n == 1) {
for (int i = t - 1; i >= 0; i--) {
for (int j = i; j > 0; j--)
System.out.print(" ");
System.out.println(str.charAt(i));
}
} else if (n == 2) {
for (int i = t - 1; i >= 0; i--) {
for (int j = 0; j < (t / 2); j++)
System.out.print(" ");
System.out.println(str.charAt(i));
}
} else if (n == 3) {
for (int i = t - 1; i >= 0; i--) {
for (int j = t - 1; j > i; j--)
System.out.print(" ");
System.out.println(str.charAt(i));
}
} else if (n == 5) {
for (int i = 0; i < t; i++) {
for (int j = i + 1; j < t; j++)
System.out.print(" ");
System.out.println(str.charAt(i));
}
} else if (n == 6) {
for (int i = 0; i < t; i++) {
for (int j = 0; j < t / 2; j++)
System.out.print(" ");
System.out.println(str.charAt(i));
}
} else if (n == 7) {
for (int i = 0; i < t; i++) {
for (int j = 0; j < i; j++)
System.out.print(" ");
System.out.println(str.charAt(i));
}
}
}
}
}

AC的C语言代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h> char name[100];
int n; int main()
{
while( scanf("%s",name) !=EOF ){
int t = strlen(name);
scanf("%d",&n);
n %= 8;
if( n < 0 )
n += 8;
if( n == 0 )
printf("%s\n",name);
else if( n==4 ){
for( int i=t-1 ; i>=0 ; i-- )
printf("%c",name[i]);
printf("\n");
}
else if( n == 1 ){
for( int i=t-1; i>=0 ; i-- ){
for( int j=i ; j>0 ; j-- )
printf(" ");
printf("%c\n",name[i]);
}
}
else if( n == 2 ){
for( int i=t-1 ; i>=0 ; i-- ){
for( int j=0 ; j<(t/2) ; j++ )
printf(" ");
printf("%c\n",name[i]);
}
}
else if( n == 3 ){
for( int i=t-1 ; i>=0 ; i-- ){
for( int j=t-1 ; j>i ; j-- )
printf(" ");
printf("%c",name[i]);
printf("\n");
}
}
else if( n == 5 ){
for( int i=0 ; i<t ; i++ ){
for( int j=i+1 ; j<t ; j++ )
printf(" ");
printf("%c\n",name[i]);
}
}
else if( n == 6 ){
for( int i=0 ; i<t ; i++ ){
for( int j=0 ; j<t/2 ; j++ )
printf(" ");
printf("%c\n",name[i]);
}
}
else if( n == 7 ){
for( int i=0 ; i<t ; i++ ){
for( int j=0 ; j<i ; j++ )
printf(" ");
printf("%c\n",name[i]);
}
}
}
return 0;
}

HDOJ(HDU) 2137 circumgyrate the string(此题用Java-AC不过!坑)的更多相关文章

  1. HDOJ/HDU 1328 IBM Minus One(水题一个,试试手)

    Problem Description You may have heard of the book '2001 - A Space Odyssey' by Arthur C. Clarke, or ...

  2. HDOJ/HDU 2537 8球胜负(水题.简单的判断)

    Problem Description 8球是一种台球竞赛的规则.台面上有7个红球.7个黄球以及一个黑球,当然还有一个白球.对于本题,我们使用如下的简化规则:红.黄两名选手轮流用白球击打各自颜色的球, ...

  3. HDOJ(HDU) 2090 算菜价(简单水题、)

    Problem Description 妈妈每天都要出去买菜,但是回来后,兜里的钱也懒得数一数,到底花了多少钱真是一笔糊涂帐.现在好了,作为好儿子(女儿)的你可以给她用程序算一下了,呵呵. Input ...

  4. HDOJ(HDU) 1555 How many days?(水题)

    Problem Description 8600的手机每天消费1元,每消费K元就可以获赠1元,一开始8600有M元,问最多可以用多少天? Input 输入包括多个测试实例.每个测试实例包括2个整数M, ...

  5. HDU 5842 Lweb and String 水题

    Lweb and String 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5842 Description Lweb has a string S ...

  6. HDOJ/HDU 2561 第二小整数(水题~排序~)

    Problem Description 求n个整数中倒数第二小的数. 每一个整数都独立看成一个数,比如,有三个数分别是1,1,3,那么,第二小的数就是1. Input 输入包含多组测试数据. 输入的第 ...

  7. HDOJ(HDU) 2139 Calculate the formula(水题,又一个用JavaAC不了的题目)

    Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) 看到这个时间,我懵逼了... 果然,J ...

  8. HDOJ(HDU) 2123 An easy problem(简单题...)

    Problem Description In this problem you need to make a multiply table of N * N ,just like the sample ...

  9. HDOJ(HDU) 1562 Guess the number(水题,枚举就行)

    Problem Description Happy new year to everybody! Now, I want you to guess a minimum number x betwwn ...

随机推荐

  1. 利用html+ashx实现aspx的功能

    最近准备学习下ASP.NET,初期在网上看了些视频教程,准备将自己学习的东西整理整理,留着日后可以参考参考. 本文采用了html.ashx实现aspx,实现了一个最简单的动态网页效果,开发环境是VS2 ...

  2. 浅淡Webservice、WSDL三种服务访问的方式(附案例)

    Webservice Webservice是使应用程序以与平台和编程语言无关的方式进行相互通信技术. eg:站点提供访问的数据接口:新浪微博.淘宝. 官方解释:它是一种构建应用程序的普遍模型,可以在任 ...

  3. CSS3美化表单控件

    表单的默认控件在不同的浏览器中的样式不同,用户体验很差.用CSS3可以实现表单控件的美化,可以提供更好的用户体验.不足之处就是浏览器的兼容性问题. 一.下拉控件 效果图: 下拉控件的布局结构: < ...

  4. HttpClient的get+post请求使用

    啥都不说,先上代码 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReade ...

  5. spring data jpa Specification 例子

    /** * 封装查询条件 * * @param baseQueryDTO * @return */ private Specification<ActivityBase> getSpeci ...

  6. 注解SpringMVC

    <!--注解映射器 --> <bean class="org.springframework.web.servlet.mvc.method.annotation.Reque ...

  7. ubuntu 14.04.02 LTS 启动项误写入 /dev/sda1 (win 7 loader) 修复

    问题描述: 在win7下安装Ubuntu14.04,由于启动项 /boot loader 安装位置错误(/dev/sda1 (win 7 loader) )导致无法进入Windows(在GRUB界面能 ...

  8. C# WinFrom 编写正则表达式验证类

    public class ValidationRegex { /// <summary> /// 正则表达式字符串 /// </summary> public static s ...

  9. Bootstrap_表单_表单提示信息

    平常在制作表单验证时,要提供不同的提示信息.在Bootstrap框架中也提供了这样的效果.使用了一个"help-block"样式,将提示信息以块状显示,并且显示在控件底部. < ...

  10. 【Linux】常用命令

    一.文件结构     /:       根目录 /bin:    系统所需要的那些命令位于此目录. /boot:   Linux的内核及引导系统程序所需要的文件目录,GRUB或LILO系统引导管理器也 ...