Tsinsen 题解 1025-1033(已完结)

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

1025 字符串对比

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.nextLine();
        String b = sc.nextLine();
        sc.close();
        int result = f(a, b);
        System.out.println(result);
    }
    public static int f(String a, String b) {
        if (a.length() != b.length()) {
            return 1;
        } else {
            if (a.equals(b)) {
                return 2;
            } else if (a.equalsIgnoreCase(b)) {
                return 3;
            } else {
                return 4;
            }
        }
    }
}


1026 字符统计

import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        sc.close();
        int len = s.length();
        char[] a = s.toCharArray();
        int[] count = new int[26];
        for (int i = 0; i < len; i++) {
            count[a[i] - 'a']++;
        }
        for (int i = 0; i < 26; i++) {
            if (count[i] != 0) {
                System.out.println((char) ('a' + i) + " " + count[i]);
            }
        }
    }
}


1027 拼写检查 —见 详解


1028 选择计算 

import java.util.*;
public class Main {
    public static int f1(int m,int n) {
        if(m < n) {
            int temp = m;
            m = n;
            n = temp;
        }
        if(m % n == 0) {
            return n;
        }else {
            return f1(n, m % n);
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();
        sc.close();
        if(z==1) {
            System.out.println(x+y);
        }
        if(z==2) {
            System.out.println(x-y);
        }
        if(z==3) {
            System.out.println(x * y);
        }
        if(z==4) {
            System.out.println((int)(x/y));
        }
        if(z==5) {
            System.out.println(x % y);
        }
        if(z==6) {
            System.out.println(f1(x, y));
        }
        if(z==7) {
            System.out.println(x*y/f1(x, y));
        }
    }
}


1029 补写函数 (本题不能用java提交)

#include<iostream>
using namespace std;
int maxmin_0(int a, int b, int c, int *max, int *min)
{
    *max=a>b?(a>c?a:c):(b>c?b:c);
    *min=a<b?(a<c?a:c):(b<c?b:c);
    return 0;
}
int maxmin_1(int a, int b, int c, int &max, int &min)
{
    max=a>b?(a>c?a:c):(b>c?b:c);
    min=a<b?(a<c?a:c):(b<c?b:c);
    return 0;
}


1030 球队排名 —见 详解


1031 画三角形1

public class Main {
    public static void main(String args[]){
        for(int i=1;i<=15;i++){
            for(int j=1;j<=2*i-1;j++){
                char result=(char)(Math.abs(i-j)+'A');
                System.out.print(result);
            }
            System.out.println();
        }   
    }
}


1032 画三角形2

import java.util.*;
public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.close();
        for(int i=1;i<=n;i++){
            for(int j=1;j<=2*i-1;j++){
                char result=(char)(Math.abs(i-j)+'A');
                System.out.print(result);
            }
            System.out.println();
        }   
    }
}


1033 绘制图形

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值