题解 | 单组_二维字符数组-Java

单组_二维字符数组

https://www.nowcoder.com/practice/2316c1fedff14a8d91694a26c9da3310

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int n = in.nextInt();
        int m = in.nextInt();
        StringBuilder sb = new StringBuilder();
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String s = in.nextLine();
            sb.append(s);
        }
        char[] res = sb.reverse().toString().toCharArray();
        for (int i = 0; i < n * m; i++) {
            System.out.print(res[i]);
            if ((i + 1) % m == 0) {
                System.out.println();
            }
        }
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
2025-12-12 19:18
wxg 开发 24Kx17 其他
不太迷人的反派_:得看背景,本科24,比我工作三年都高了
点赞 评论 收藏
分享
2025-12-23 16:48
深圳大学 前端工程师
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务