「题目代码」P1029~P1033(Java)

1029 C基础-求解方程

import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Main
{
    public static void main(String args[])
    {
        for(int i=100;i<=999;++i)
        {// 这特么不需要排除相同项
            int j=1333-i; if(/* i>j || */j<100 || j>=1000) continue;
            int ig=i%10,is=(i/10)%10,ib=i/100,
                jg=j%10,js=(j/10)%10,jb=j/100;

            if(ig==jb && ib==jg && is==js)
            {
                System.out.println(i+"+"+j+"="+1333);
            }
        }
    }
}

1030 C基础-选择半径

import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Main
{
    public static void main(String args[])
    {
        Scanner cin=new Scanner(System.in);
        for(int i=1;i<=10;++i)
        {
            double s=i*3.14159*i;
            if(s>=40.0 && s<=90.0)
            {
                System.out.printf("r=%d area=%.2f\n",i,s);
            }
        }
    }
}

1031 C基础-选择排序

/* Insertion Sort - P1031
 * The algorithm divides the input list into two parts: the sublist of items    
 * already sorted, which is built up from left to right at the front (left) of
 * the list, and the sublist of items remaining to be sorted that occupy the
 * rest of the list. Initially, the sorted sublist is empty and the unsorted
 * sublist is the entire input list. The algorithm proceeds by finding the
 * smallest (or largest, depending on sorting order) element in the unsorted
 * sublist, exchanging (swapping) it with the leftmost unsorted element
 * (putting it in sorted order), and moving the sublist boundaries one element
 * to the right.
 */
import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Main
{
    public static void main(String args[])
    {
        Scanner cin=new Scanner(System.in);
        int[] arr=new int[15];
        for(int i=1;i<=10;++i)
        {
            arr[i]=cin.nextInt();
        }
        for(int i=1;i<=10;++i)
        {
            int minId=i;
            for(int j=i;j<=10;++j)
                if(arr[minId]>arr[j])
                    minId=j;
            swap(arr,minId,i);
        }
        for(int i=1;i<=10;++i)
            System.out.println(arr[i]);
    }
    // a mainstream implementation due to limitation of Java itself.
    public static void swap(int[] arr, int a, int b) {  
        int temp = arr[a];  
        arr[a] = arr[b];  
        arr[b] = temp;  
    }
}

1032 C基础-局部求和

import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Main
{
    public static void main(String args[])
    {
        Scanner cin=new Scanner(System.in);
        int[] arr=new int[25];
        for(int i=1;i<=20;++i)
        {
            arr[i]=cin.nextInt();
        }
        for(int i=1;i<=20;++i)
        {
            for(int j=1;j<=20;++j)
            {
                if(i==j) continue;
                if(arr[i]%arr[j]==0) {System.out.println(arr[i]); break;}
            }
        }
    }
}

1033 C基础-对角线和

import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Main
{
    public static void main(String args[])
    {
        Scanner cin=new Scanner(System.in);
        int[][] arr=new int[5][5];
        for(int i=1;i<=3;++i)
        {
            for(int j=1;j<=3;++j)
                arr[i][j]=cin.nextInt();
        }
        System.out.println((int)(arr[1][1]+arr[2][2]+arr[3][3]));
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值