Tsinsen 题解 1044-1052(已完结)

附:友情链接之 Tsinsen 第一卷 题解 1000-1024(已完结)          

                       Tsinsen 第一卷 题解 1025-1033(已完结)  

                         Tsinsen 第一卷 题解 1034-1043(已完结)


1044 Fibonacii 数列求和

import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            } else if (n == 1) {
                System.out.println(1);
            } else if (n == 2) {
                System.out.println(2);
            } else {
                int[] f = new int[30];
                f[1] = f[2] = 1;
                int sum = 0;
                for (int i = 3; i <= n; i++) {
                    f[i] = f[i - 1] + f[i - 2];
                    sum += f[i];
                }
                System.out.println(sum+2);
            }
        }
    }
}


1045 交换

import java.io.*;
import java.util.*;
class Reader {  
    static BufferedReader reader;  
    static StringTokenizer tokenizer;  
  
    static void init(InputStream input) {  
        reader = new BufferedReader(new InputStreamReader(input));  
        tokenizer = new StringTokenizer("");  
    }  
  
    static String next() throws IOException {  
        while (!tokenizer.hasMoreTokens()) {  
            tokenizer = new StringTokenizer(reader.readLine());  
        }  
        return tokenizer.nextToken();  
    }  
  
    static int nextInt() throws IOException {  
        return Integer.parseInt(next());  
    }  
  
    static double nextDouble() throws IOException {  
        return Double.parseDouble(next());  
    }  
}  
class Main {
    public static void main(String[] args) throws IOException {
        Reader.init(System.in);
        int t = Reader.nextInt();
        for (int i = 0; i < t; i++) {
            int N = Reader.nextInt();
            int[] a = new int[N + 1];
            int M = Reader.nextInt();
            int[][] b = new int[M + 1][3];
            for (int j = 1; j <= N; j++) {
                a[j] = Reader.nextInt();
            }
            for (int k1 = 1; k1 <= M; k1++) {
                for (int k2 = 1; k2 <= 2; k2++) {
                    b[k1][k2] = Reader.nextInt();
                }
                int x = b[k1][1];
                int y = b[k1][2];
                int temp = a[x];
                a[x] = a[y];
                a[y] = temp;
            }
            for (int k3 = 1; k3 <= N; k3++) {
                System.out.println(a[k3]);
            }
        }
    }
}

1046 加法器 —见 详解


1047 做明智的消费者

import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] a = new int[n + 1][m + 1];
        int[] flag = new int[m + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        for (int i = 1; i <= m; i++) {
            int min = 100000;
            for (int j = n; j >= 1; j--) {
                if (a[j][i] == 0) {
                    continue;
                } else if (a[j][i] < min) {
                    min = a[j][i];
                    flag[i] = j;
                }
            }
        }
        for (int i = 1; i <= m; i++) {
            System.out.print(flag[i] + " ");
        }
    }
}

1048 数字三角形

import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] a = new int[11][11];
        a[0][0] = 1;
        int i, j, k;
        for (i = 0, j = 0, k = 2; k <= n * (n + 1) / 2;) {
            while (i + 1 < n && a[i + 1][j] == 0)
                a[++i][j] = k++;
            while (j + 1 < n && a[i][j + 1] == 0)
                a[i][++j] = k++;
            while (i - 1 > -1 && j - 1 > -1 && a[i - 1][j - 1] == 0)
                a[--i][--j] = k++;
        }
        for (i = 0; i < n; i++) {
            for (j = 0; j <= i; j++) {
                System.out.print(a[i][j] + " ");
            }
            System.out.println();
        }
    }
}


1049 命题逻辑 —见 详解


1050 碱基比例

import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        int count=0;
        for(int i=0;i<a.length();i++){
            if(a.charAt(i)=='G' || a.charAt(i)=='C'){
                count++;
            }
        }
        double result = count * 100.0/a.length();
        System.out.println(Math.round(result));
    }
}


1051 DNA序列

import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] A = new int[11];
        int[] G = new int[11];
        int[] C = new int[11];
        int[] T = new int[11];
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            String a = sc.next();
            char[] b = a.toCharArray();
            for (int j = 0; j < b.length; j++) {
                if (b[j] == 'A') {
                    A[j]++;
                }
                if (b[j] == 'G') {
                    G[j]++;
                }
                if (b[j] == 'C') {
                    C[j]++;
                }
                if (b[j] == 'T') {
                    T[j]++;
                }
            }
        }
        for (int i = 0;A[i]!=0 ||G[i]!=0 || C[i]!=0 || T[i]!=0; i++) {
            char a = 0;
            if (A[i] >= C[i] && A[i] >= G[i] && A[i] >= T[i]) {
                a = 'A';
            }
            if (C[i] > A[i] && C[i] >= G[i] && C[i] >= T[i]) {
                a = 'C';
            }
            if (G[i] > A[i] && G[i] > C[i] && G[i] >= T[i]) {
                a = 'G';
            }
            if (T[i] > A[i] && T[i] > G[i] && T[i] > C[i]) {
                a = 'T';
            }
            System.out.print(a);
        }
    }
}


1052 数的读法 —见 详解

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值