试题 算法提高 桌上的书java

试题 算法提高 桌上的书java

初学

笨方法

看看就行

代码:

import java.util.Scanner;

public class Main {
    public static void main(String[] arg) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        int a = n;
        String[] dou = new String[m];
        String[] book1 = new String[n + m];
        for(int i = 0;i < n;i++) {
            book1[n - i - 1] = sc.next();
        }
        for(int i = 0;i < m;i++) {
            dou[i] = sc.next();
        }
        for(int i = 0;i < m;i++) {
            String name = dou[i];
            char[] name1 = name.toCharArray();
            if (name1[0] == 'A') {
                book1[a] = dou[i].substring(4, name1.length - 1);
                a++;
            } else if (name1[0] == 'R') {
                if(a >= k) {
                    for (int j = 0; j < k / 2; j++) {
                        String temp = book1[a - 1 - j];
                        book1[a - 1 - j] = book1[a - k + j];
                        book1[a - k + j] = temp;
                    }
                }else{
                    for (int j = 0; j < a / 2; j++) {
                        String temp = book1[a - 1 - j];
                        book1[a - 1 - j] = book1[j];
                        book1[j] = temp;
                    }
                }
            }
        }
        for(int i = 0;i < book1.length;i++) {
            if(book1[book1.length - i - 1] == null) {
                continue;
            }
            System.out.println(book1[book1.length - i - 1]);
        }
    }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值