蓝桥杯校赛选拔小试题记录

这里写图片描述

1.

public class Main {
    public static void main(String[] args) {
    String A = "Hello World";
    String B = "Welcome to attend the contest";
    String C = "Achieve good mark";
    System.out.println(Translatestr(A));
    System.out.println(Translatestr(B));
    System.out.println(Translatestr(C));

    }

    private static StringBuilder Translate(String str) {
        String[] data = str.split(" ");
        StringBuilder temp = new StringBuilder();
        for (int i = 0; i < data.length; i++) {
            data[i] = Translatestr(data[i]);
            temp.append(data[i]);
        }
        return temp;
    }

    private static String Translatestr(String data) {

        char [] temp = data.toCharArray();
        char c;
        for (int i = 0; i < temp.length/2; i++) {
            c = temp[i];
            temp[i] = temp[temp.length-i-1];
            temp[temp.length-i-1] = c;
            if (i == temp.length-i) {
                break;
            }
        }
        return new String(temp);

    }
}

2.

public class Sort {
    public static void main(String[] args) {
        int a[] = {8,21,7,9,10,13};
        sort(a);
        for (int i : a) {
            System.out.print(i+" ");
        }
    }

    private static void sort(int[] a) {
        for (int i = 0; i < a.length-1; i++) {
            for (int j = 0; j < a.length-1-i; j++) {
                if (a[j]>a[j+1]) {
                    a[j] = a[j] ^ a[j+1];
                    a[j+1] = a[j] ^ a[j+1];
                    a[j] = a[j] ^ a[j+1];
                }
            }
        }
    }
}

3.

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {

    public static void main(String[] args) {
        SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd");
        SimpleDateFormat sdf2 = new SimpleDateFormat("E");
        String str = "2014-11-28";
        Date date = null;
        try {
            date = sdf.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        if (date.getDate()!=13||date.getDate()!=5) {
//          if (sdf2.format(date).equals("星期五")) {
//              System.out.println("这天是黑色星期五");
//          }
            if (date.getDay()==5) {
                System.out.println("这天是黑色星期五");
            }
        }
    }
}

4.

public class Main {
    public static void main(String[] args) {
        int a = 15;
        findOrder(a);

    }

    private static void findOrder(int a) {
        String str = "";
        int sum = 0;
        for (int i = a-1; i > 0; i--) {
            sum = 0;
            str = "";
            for (int j = i; j > 0; j--) {
                sum += j;
                str += String.valueOf(j) + "+";
                if (sum == 15) {
                    System.out.println(str.substring(0, str.length()-1));
                    break;
                }else if(sum < 15) {
                    continue;
                }else {
                    break;
                }
            }
        }
    }

}
文章导航