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 ...
随机推荐
- E/Trace: error opening trace file: No such file or directory
E/Trace: error opening trace file: No such file or directory (2) 有这一个错误,想了一下,然后发现是 AdroidManifest.xm ...
- Oracle主键自动生成_表and存储过程
-- Create table create table T_EB_SYS_DN_SEQUENCE_CONFIG ( sequence_id VARCHAR2(36) default sys_guid ...
- JAVA 环境变量
Java是由Sun公司开发的一种应用于分布式网络环境的程序设计语言,Java语言拥有跨平台的特性,它编译的程序能够运行在多种操作系统平台上,可以实现“一次编写,到处运行”的强大功能. 工具/原料 JD ...
- c# web 删除时弹出提示框
方法1: 在控件中增加属性 <asp:Button ID="btnSub" runat="server" Text="提交" oncl ...
- 使用highlight.js高亮你的代码
在逛别人的博客的时候,看见别人的代码的例子使用了高亮的语法,无论是java,js还是php等等语言,都会自动的对关键字进行高亮. 于是在前几天自己写了一个博客,遇到code时,自然就想到了别人网站如何 ...
- Visual Studio vs2010 去掉中文注释红色下划线;去掉代码红色下划线;
vs去掉下挂线也分两种: 1.去掉中文注释红色下划线,需要去掉VisualAssist下划线鸡肋功能: 1.选择Visual AssistX Options: 2.把如图所示的勾去掉,解决. 以后再次 ...
- Codeforces 474E - Pillars
一眼看上去非常像最长不下降子序列. 然后比赛的时候对每个答案长度为k的序列,维护最后一个数的最大值和最小值. 当时不知道为什么认为从长度最长倒推至前面不会太长,于是心满意足地敲了个O(n^2).结果T ...
- jQuery慢慢啃之核心(一)
1. $("div > p"); div 元素的所有p子元素. $(document.body).css( "background", "bla ...
- php配置虚拟主机的配置步骤(hosts、httpd.conf、vhosts.conf)1.配置本地的dns文件2.配置apache的主配置文件3.配置Apache的虚拟主机
1.域名解析(DNS) 找到C:\Windows\System32\drivers\etc目录下的hosts文件,在里面进行添加对应的内容
- 如何用angularjs制作一个完整的表格之五__完整的案例
由于本人也是边学边写,因此整理的比较乱,下面放出我例子的完整代码,方便大家交流测试,如有问题欢迎评论 首先,表格采用的是BootStrap样式编辑的,主要使用的是angularjs,为了方便也有jQu ...