信用卡中心笔试

就过了第一题,5分钟写完,后两题直接心态爆炸,没A,很烦
求后两题
第一题代码:(其实就是个很简单的规律,R和L挨着的就会一直在这两个点晃悠)
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String[] s=sc.nextLine().trim().split("");
        int[] t=new int[s.length];
        for(int i=0;i<s.length;i++) {
            t[i]=0;
        }
        for(int i=0;i<s.length;i++) {
            if(s[i].equals("R")) {
                int j=i+1;
                int count=0;
                int jcount=0;
                while(s[j].equals("R")) {
                    count++;
                    j++;
                }
                if(count%2==1) {
                    t[j]++;
                }else {
                    t[j-1]++;
                }
            }
            if(s[i].equals("L")) {
                int j=i-1;
                int count=0;
                int jcount=0;
                while(s[j].equals("L")) {
                    count++;
                    j--;
                }
                if(count%2==1) {
                    t[j]++;
                }else {
                    t[j+1]++;
                }
            }
        }
        for(int i=0;i<t.length;i++) {
            System.out.print(t[i]+" ");
        }
    }

}


#笔试题目##秋招#
全部评论

相关推荐

评论
点赞
5
分享

创作者周榜

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