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]));
}
}