HDOJ(HDU) 2137 circumgyrate the string(此题用Java-AC不过!坑)
此题如果有用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不过!坑)的更多相关文章
- HDOJ/HDU 1328 IBM Minus One(水题一个,试试手)
Problem Description You may have heard of the book '2001 - A Space Odyssey' by Arthur C. Clarke, or ...
- HDOJ/HDU 2537 8球胜负(水题.简单的判断)
Problem Description 8球是一种台球竞赛的规则.台面上有7个红球.7个黄球以及一个黑球,当然还有一个白球.对于本题,我们使用如下的简化规则:红.黄两名选手轮流用白球击打各自颜色的球, ...
- HDOJ(HDU) 2090 算菜价(简单水题、)
Problem Description 妈妈每天都要出去买菜,但是回来后,兜里的钱也懒得数一数,到底花了多少钱真是一笔糊涂帐.现在好了,作为好儿子(女儿)的你可以给她用程序算一下了,呵呵. Input ...
- HDOJ(HDU) 1555 How many days?(水题)
Problem Description 8600的手机每天消费1元,每消费K元就可以获赠1元,一开始8600有M元,问最多可以用多少天? Input 输入包括多个测试实例.每个测试实例包括2个整数M, ...
- HDU 5842 Lweb and String 水题
Lweb and String 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5842 Description Lweb has a string S ...
- HDOJ/HDU 2561 第二小整数(水题~排序~)
Problem Description 求n个整数中倒数第二小的数. 每一个整数都独立看成一个数,比如,有三个数分别是1,1,3,那么,第二小的数就是1. Input 输入包含多组测试数据. 输入的第 ...
- HDOJ(HDU) 2139 Calculate the formula(水题,又一个用JavaAC不了的题目)
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) 看到这个时间,我懵逼了... 果然,J ...
- 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 ...
- HDOJ(HDU) 1562 Guess the number(水题,枚举就行)
Problem Description Happy new year to everybody! Now, I want you to guess a minimum number x betwwn ...
随机推荐
- eclipse下:selenium+python自动化之Chrome driver
1.下载chromedriver.exe文件: 2.下载的chromedriver.exe文件放置在chrome的安装目录下XXX\Chrome\Application\ ; 3.设置path环境变量 ...
- 文字排版--下划线(text-decoration:underline)
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- jQuery实现的向下推送图文信息滚动效果
HTML 我们以新浪微博信息滚动为背景,html中包含了多条微博图文信息,结构如下: <div id="con"> <ul> <li> < ...
- WCF服务对象实例化基础
很多情况下,我们都需要控制wcf服务端对象的初始化方式,用来控制wcf实例在服务端的存活时间. Wcf框架提供了三种创建wcf实例的方式. WCF服务对象实例化基础 在普通的WCF请求和相应过程中,将 ...
- 第一个程序点亮一个LED灯
#include <reg52.h> // 引用52包文件 可以理解为命名空间 sbit P1_0 = P1^0; // 定义P1管脚0 void main() ...
- PHP学习之中数组-遍历一维数组【2】
在PHP学习之中数组[1]中学会怎么创建一个数组,如果PHP学习之中数组[1]中的元素多的话,我们访问元素又是一个问题了,下面我们就使用for语句while,foreach来遍历我们的数组: < ...
- django-orm-standalone
django-orm-standalone script via:https://github.com/masnun/django-orm-standalone/ # Django specific ...
- github的访问变慢了
以下个人观点:把操作系统的自主研究还有处理器自主研究列入重点,还有互联网上的种种动作,我发现里面似乎揭示了某些迹象,科研真的不应该以牺牲大部分人的河法全益为代价甚至目的.当某一天win不可能出现在出厂 ...
- spart快速大数据分析学习提纲(一)
Spart是什么 Spart是一个用来实现快速而而通用的集群计算平台. 在速度方面,Spart扩展了广泛使用的Mapreduce计算模型,而且高效的支持更多的计算模式,包括交互式查询和流处理.Spar ...
- 解决方案-Microsoft Visual Studio 2012 已停止工作
问题: 根本解决方案: 用管理员模式运行. 找到软件的安装目录 \Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe 然后如何保存管理员权限运行呢? ...