Hdoj (HDU) 2137 circumgyrate The string (this problem with JAVA-AC but!) Pit

Source: Internet
Author: User

If the problem is useful javaacdsee, please comment, thank you.

Problem Description
Give you a string, just circumgyrate. The number n means just circumgyrate the string N times, and each time you circumgyrate the string for the degree antic Lockwise.

Input
There is a string and a integer N. The length of the odd, so the center of the string would not be changed, and the string are always Hori Zontal at the beginning. The length of the string would not be exceed, so we can see the complete result on the screen.

Output
For each case, print the circumgrated string.

Sample Input
Asdfass 7

Sample Outputa s  d   f    a     s      s

The topic means simple:
Enter a string and an integer n,n to rotate the string counterclockwise by n 45° and output the rotated shape.

Note that n can be negative, and if it is negative, it can be rotated clockwise.

Similar to the HDU2135 problem. That's the matrix rotation, and this is the string rotation.
The two methods are the same, find out the loop section output separately.
The string rotation of the problem 8 times, you can go back to the original position, so on 8 to take the surplus, the output of 8 different cases can be.

There is a problem with this question, I do not know other people met no, this topic with JAVAAC not ...
Here is the Java code for WA, and the C language code for AC. -You can compare them.
Java This code is absolutely no problem, at least I have not found the wrong, if there is found, please inform, thank you.

WA's Java code:

Package Cn.hncu.acm;import Java.util.Scanner; Public classP2137 { Public Static void Main(string[] args) {Scanner SC =NewScanner (System.inch); while(Sc.hasnext ()) {String str = sc.next ();intn = sc.nextint (); N%=8;if(N <0) n + =8;intt = str.length ();if(n = =0) System. out. println (str);Else if(n = =4) { for(inti = t-1; I >=0; i--) System. out. Print (Str.charat (i)); System. out. println (); }Else if(n = =1) { for(inti = t-1; I >=0; i--) { for(intj = i; J >0; j--) System. out. Print (" "); System. out. println (Str.charat (i)); }            }Else if(n = =2) { for(inti = t-1; I >=0; i--) { for(intj =0; J < (t/2); J + +) System. out. Print (" "); System. out. println (Str.charat (i)); }            }Else if(n = =3) { for(inti = t-1; I >=0; i--) { for(intj = T-1; J > i; j--) System. out. Print (" "); System. out. println (Str.charat (i)); }            }Else if(n = =5) { for(inti =0; I < T; i++) { for(intj = i +1; J < T; J + +) System. out. Print (" "); System. out. println (Str.charat (i)); }            }Else if(n = =6) { for(inti =0; I < T; i++) { for(intj =0; J < T/2; J + +) System. out. Print (" "); System. out. println (Str.charat (i)); }            }Else if(n = =7) { for(inti =0; I < T; i++) { for(intj =0; J < I; J + +) System. out. Print (" "); System. out. println (Str.charat (i)); }            }        }    }}

C language code for AC:

#include <stdio.h>#include <stdlib.h>#include <string.h>Char name[ -];intNintMain () { while(SCANF ('%s', name)!=eof) {intt = strlen (name); scanf"%d", &n); N%= 8;if(N <0) n + =8;if(n = =0)printf('%s\ n ', name);Else if(n==4){ for(inti=t-1; i>=0; i--)printf("%c", Name[i]);printf("\ n"); }Else if(n = =1){ for(inti=t-1; i>=0; i--) { for(intJ=i; J>0; j--)printf(" ");printf("%c\ n", Name[i]); }             }Else if(n = =2){ for(inti=t-1; i>=0; i--) { for(intj=0; j< (t/2) ; J + +)printf(" ");printf("%c\ n", Name[i]); }             }Else if(n = =3){ for(inti=t-1; i>=0; i--) { for(intj=t-1; J>i; j--)printf(" ");printf("%c", Name[i]);printf("\ n"); }             }Else if(n = =5){ for(intI=0; I<t; i++) { for(intj=i+1; J<t; J + +)printf(" ");printf("%c\ n", Name[i]); }             }Else if(n = =6){ for(intI=0; I<t; i++) { for(intj=0; j<t/2; J + +)printf(" ");printf("%c\ n", Name[i]); }              }Else if(n = =7){ for(intI=0; I<t; i++) { for(intj=0; J<i; J + +)printf(" ");printf("%c\ n", Name[i]); }                  }      }return 0; }

Hdoj (HDU) 2137 circumgyrate The string (this problem with JAVA-AC but!) Pit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.