此题如果有用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. oracle 导出导入数据

    在window的运行中输出cmd,然后执行下面的一行代码, imp blmp/blmp@orcl full=y file=D:\blmp.dmp OK,问题解决.如果报找不到该blmp.dmp文件,就 ...

  2. 函数对象的prototype总结

    通过看 http://www.cnblogs.com/mindsbook/archive/2009/09/19/javascriptYouMustKnowPrototype.html 该文章和对代码的 ...

  3. POJ 3468.A Simple Problem with Integers 解题报告

    用树状数组和线段树会比较简单,这里用这道题来学习Splay. 第一次写,代码比较丑 /* 初始化添加一个key值足够大的结点 保证每个需要的结点都有后继 */ #include <iostrea ...

  4. 【POJ2886】【线段树】Who Gets the Most Candies?

    Description N children are sitting in a circle to play a game. The children are numbered from 1 to N ...

  5. IOS下双击背景, touchmove, 阻止页面背景scroll.

    ios prevent dblclick(tap) page scrollhtml add:("minimal-ui" is very important) <meta na ...

  6. Linux技巧总结(个人经验版)

    1:善用桌面:1.图形界面的编辑,2.终端只要开机就在第2桌面,3.浏览器在第3桌面,4.娱乐在第4桌面. 2:cd命令中,输入中文目录很不方便,用 ln -s 桌面 desktop 创建软链接,不必 ...

  7. 自定义复选框 checkbox 样式

    默认的复选框样式一般在项目中都很少用 ,看起来也丑丑的.这里提供一个优化样式后的复选框.原理就是隐藏掉默认样式,在用设计好的样式替代 html结构 <div> <input type ...

  8. apache rewrite .htaccess 站点内容重定向实例

    <IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_FILENA ...

  9. jsonp是什么以及jsonp的使用

    1概述 Jsonp(JSON with Padding)是资料格式 json 的一种“使用模式”,可以让网页从别的网域获取资料.由于同源策略,一般来说位于 server1.example.com 的网 ...

  10. Dao操作的抽取,BaseDao

    Dao操作通用的步骤: 0. 写SQL语句 1. 获取连接 2. 创建stmt 3. 执行sql a) 更新 b) 查询 4. 关闭/异常 代码: BaseDao /** * 通用的dao,自己写的所 ...