当前位置: 代码迷 >> 综合 >> HDOJ 1033 Edge
  详细解决方案

HDOJ 1033 Edge

热度:70   发布时间:2023-10-21 18:23:29.0

HDACM 1033


题意就是 画线,A表示顺时针旋转90度,v表示逆时针旋转90度。


import java.util.Scanner;public class Main{public static void main(String[] args) {Scanner sc = new Scanner(System.in);while (sc.hasNext()) {String str = sc.next();System.out.println("300 420 moveto");System.out.println("310 420 lineto");int x = 310;int y = 420;int dirct = 1; // 1左,3右,0上,2下int i = 0;while (i < str.length()) {if (str.charAt(i) == 'A') {dirct = (dirct + 1) % 4;} else {dirct = (dirct - 1 + 4) % 4;}switch (dirct) {case 0:y += 10;break;case 1:x += 10;break;case 2:y -= 10;break;case 3:x -= 10;break;}System.out.println(x+" "+y+" lineto");i++;}System.out.println("stroke");System.out.println("showpage");}sc.close();}}