UVA232java

依旧是非常复杂的输入输出
输出的数字序号要%3d的格式
每组输出间需有空行,最后不能有空行
纵向输出时打印的顺序是按之前的计数,我排了个序

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class UVA232 {
    static class st{
        String s;
        int count;
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int h=1;
        while(true){
            int r=sc.nextInt();
            if(r==0)break;
            if(h!=1) System.out.println();
            System.out.println("puzzle #"+h+":");
            h++;
            int c=sc.nextInt();
            char[][] map=new char[r][c];
            int[][] count=new int[r][c];
            int k=1;
            for (int i = 0; i < r; i++) {
                map[i]=sc.next().toCharArray();
                for (int j = 0; j < c; j++) {
                    if(map[i][j]!='*'&&(i==0||map[i-1][j]=='*'||j==0||map[i][j-1]=='*')){
                        count[i][j]=k++;
                    }
                }
            }
            System.out.println("Across");
            for (int i = 0; i < r; i++) {
                int j=0;
                while(j<=(c-1)){
                    if(count[i][j]!=0){
                        System.out.print(String.format("%3d",count[i][j]));
                        System.out.print(".");
                        while(j<=(c-1)&&map[i][j]!='*'){
                            System.out.print(map[i][j]);
                            j++;
                        }
                        System.out.println();
                    }
                    else j++;
                }
            }
            System.out.println("Down");
            st[] stcount=new st[100];
            for (int i = 0; i < 100; i++) {
                stcount[i]=new st();
            }
            int q=0;
            for (int j = 0; j < c; j++) {

                int i=0;
                while(i<=(r-1)){
                    if(count[i][j]!=0){
                        StringBuffer sb=new StringBuffer();
                        stcount[q].count=count[i][j];


                        while(i<=(r-1)&&map[i][j]!='*'){
                            sb.append(map[i][j]);

                            i++;
                        }
                        stcount[q].s=sb.toString();


                        q++;

                    }
                    else i++;
                }
            }
            Comparator<st> cmp=new Comparator<st>() {
                @Override
                public int compare(st o1, st o2) {
                    return o1.count-o2.count;
                }
            };
            Arrays.sort(stcount,0,q,cmp);
            for (int i = 0; i < q; i++) {
                System.out.print(String.format("%3d",stcount[i].count));
                System.out.print(".");
                System.out.println(stcount[i].s);
            }
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值