一共17道题
下面代码供参考
每题前面标的有题号
1114 逆序
1115 数组最小值
1116 删除元素
1117 查找数组元素
1118 数列有序
1119 一维数组排序
1120 最值交换
1121 电梯
1122 小明的调查作业
1123 最佳校友
1124 两个有序数组合并
1125 上三角矩阵的判断
1126 布尔矩阵的奇偶性
1127 矩阵乘积
1128 课程平均分
1129 第几天
1130 杨辉三角
1114
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n;
int[]a = new int[11];
n = cin.nextInt();
for (int i = 0; i < n; i++)
a[i] = cin.nextInt();
for (int i = n - 1; i >= 0; i--)
System.out.printf("%4d", a[i]);
}
}
1115
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n, num, k, ans;
n = cin.nextInt();
num = cin.nextInt();
ans = num;
k = 0;
for (int i = 1; i < n; i++)
{
num = cin.nextInt();
if (num < ans)
{
ans = num;
k = i;
}
}
System.out.println(ans + " " + k);
}
}
1116
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n, num, k;
int[] a = new int[11];
n = cin.nextInt();
for (int i = 0; i < n; i++)
{
a[i] = cin.nextInt();
}
k = cin.nextInt();
for (int i = 0; i < n; i++)
{
if (i == k)
continue;
else
{
if (i != n - 1)
System.out.print(a[i] + " ");
else
System.out.print(a[i]);
}
}
}
1117
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n, k = -1, need;
int[] a = new int[11];
n = cin.nextInt();
for (int i = 0; i < n; i++)
{
a[i] = cin.nextInt();
}
need = cin.nextInt();
for (int i = 0; i < n; i++)
{
if (a[i] == need)
{
k = i;
break;
}
}
if (k == -1)
System.out.println("Not Found");
else
{
for (int i = 0; i < n; i++)
{
if (i == k)
continue;
else
System.out.printf("%4d", a[i]);
}
}
}
}
1118
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n;
n = cin.nextInt();
int[] a = new int[n + 1];
for (int i = 0; i <= n; i++)
a[i] = cin.nextInt();
Arrays.sort(a);
for (int i = 0; i <= n; i++)
if (i != n)
System.out.print(a[i] + " ");
else
System.out.print(a[i]);
}
}
1119
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n;
n = cin.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = cin.nextInt();
Arrays.sort(a);
for (int i = 0; i < n; i++)
if (i != n - 1)
System.out.print(a[i] + " ");
else
System.out.print(a[i]);
}
}
1120
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n, MAX, MIN, k = 0;
n = cin.nextInt();
int[]a = new int[11];
for (int i = 0; i < n; i++)
a[i] = cin.nextInt();
MAX = MIN = a[0];
for (int i = 0; i < n; i++)
{
if (a[i] < MIN)
{
MIN = a[i];
k = i;
}
}
int t;
t = a[0];
a[0] = a[k];
a[k] = t;
for (int i = 0; i < n; i++)
{
if (a[i] > MAX)
{
MAX = a[i];
k = i;
}
}
t = a[n - 1];
a[n - 1] = a[k];
a[k] = t;
for (int i = 0; i < n; i++)
System.out.print(a[i] + " ");
}
}
1121
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int[] a = new int[1010];
int n, ans = 0;
n = cin.nextInt();
for (int i = 0; i < n; i++)
a[i] = cin.nextInt();
ans += a[0] * 6;
for (int i = 1; i < n; i++)
{
if (a[i] > a[i - 1])
ans += (a[i] - a[i - 1]) * 6;
else
ans += (a[i - 1] - a[i]) * 4;
}
System.out.println(ans + n * 5);
}
}
1122
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n, cnt = 0, num;
int[] vis = new int[1010];
int[] a = new int[1010];
n = cin.nextInt();
for (int i = 0; i<n; i++)
{
num = cin.nextInt();
if (vis[num] == 0)
{
vis[num] = 1;
a[cnt++] = num;
}
}
Arrays.sort(a, 0, cnt);
System.out.println(cnt);
for (int i = 0; i<cnt; i++)
System.out.print(a[i] + " ");
}
}
1123
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int[] a = new int[100];
int num, MAX = 0;
while (cin.hasNext())
{
num = cin.nextInt();
if (num == -1)
break;
a[num]++;
MAX = Math.max(a[num], MAX);
}
for (int i = 0; i <= 99; i++)
if (a[i] == MAX)
System.out.print(i + " ");
}
}
1124
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int[] a = new int[2000010];
int[] b = new int[1000010];
int n, m;
n = cin.nextInt();
for (int i = 0; i < n; i++)
a[i] = cin.nextInt();
m = cin.nextInt();
for (int i = 0; i < m; i++)
b[i] = cin.nextInt();
for (int i = n; i - n < m; i++)
{
a[i] = b[i - n];
}
Arrays.sort(a, 0, n + m);
for (int i = n + m - 1; i >= 0; i--)
System.out.print(a[i] + " ");
}
}
1125
import java.util.Scanner;
public class Main {
public static int j(int k)
{
int sum = 0;
for (int i = 1; i <= k; i++)
sum += i;
return sum;
}
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int[][] a = new int[11][11];
int n, cnt = 0;
n = cin.nextInt();
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
int num = cin.nextInt();
if (i != 0 && j != n - 1)
{
if (j < i&&num == 0)
cnt++;
}
}
if (n*n - j(n) == cnt)
System.out.print("YES");
else
System.out.print("NO");
}
}
1126
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n;
int[][] a = new int[110][110];
n = cin.nextInt();
int flag1 = 0, flag2 = 0, u = 0, v = 0;
for (int i = 0; i<n; i++)
for (int j = 0; j<n; j++)
{
a[i][j] = cin.nextInt();
}
for (int i = 0; i<n; i++)
{
int sum = 0;
for (int j = 0; j<n; j++)
{
sum += a[i][j];
}
if (sum % 2 != 0)
{
flag1 = 1;
u = i;
}
}
for (int i = 0; i<n; i++)
{
int sum = 0;
for (int j = 0; j<n; j++)
{
sum += a[j][i];
}
if (sum % 2 != 0)
{
flag2++;
v = i;
}
}
if (flag1 == 0 && flag2 == 0)
System.out.println("OK");
else
if (flag1 == 1 && flag2 == 1)
System.out.printf("Change bit(%d,%d)", u, v);
else
System.out.println("Corrupt");
}
}
1127
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int m, n, k;
int[][] a = new int[11][11];
int[][] b = new int[11][11];
int[][] c = new int[11][11];
m = cin.nextInt();
n = cin.nextInt();
k = cin.nextInt();
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
a[i][j] = cin.nextInt();
for (int i = 0; i < n; i++)
for (int j = 0; j < k; j++)
b[i][j] = cin.nextInt();
for (int i = 0; i < m; i++)
for (int j = 0; j < k; j++)
{
int sum = 0;
for (int u = 0; u < n; u++)
sum += a[i][u] * b[u][j];
c[i][j] = sum;
}
for (int i = 0; i < m; i++)
{
for (int j = 0; j < k; j++)
System.out.print(c[i][j] + " ");
System.out.println();
}
}
}
1128
import java.util.Scanner;
public class Main {
public static void main(String args[])
{
Scanner cin = new Scanner(System.in);
int m, n;
double[][] b = new double[1010][1010];
double[]a = new double[1010];
m = cin.nextInt();
n = cin.nextInt();
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
b[i][j] = cin.nextDouble();
for (int i = 0; i < n; i++)
{
double sum = 0;
for (int j = 0; j < m; j++)
sum += b[j][i];
a[i] = sum / m;
}
for (int i = 0; i < n; i++)
System.out.printf("%.2f ", a[i]);
}
}
1129
import java.util.Scanner;
public class Main {
public static int is_leap_year(int year)
{
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
return 1;
return 0;
}
public static void main(String[] args)
{
int a[][] = { { 0, 0 }, { 31, 31 }, { 28, 29 }, { 31, 31 }, { 30, 30 }, { 31, 31 }, { 30, 30 }, { 31, 31 },
{ 31, 31 }, { 30, 30 }, { 31, 31 }, { 30, 30 }, { 31, 31 } };
Scanner cin = new Scanner(System.in);
String date = cin.nextLine();
String[] s = date.split("-");
int cnt = 0, year = 0, month = 0, day = 0;
for (String i : s)
{
//System.out.println(i+" "+cnt);
if (cnt == 0)
year = Integer.parseInt(i);
if (cnt == 1)
month = Integer.parseInt(i);
if (cnt == 2)
day = Integer.parseInt(i);
cnt++;
}
// System.out.println(year+" "+month+" "+day);
int flag = 0;
if (is_leap_year(year) == 1)
flag = 1;
int sum = day;
for (int i = 1; i < month; i++)
sum += a[i][flag];
System.out.println(sum);
}
}
1130
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int[][] a = new int[40][40];
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
for (int i = 0; i < n; i++)
{
a[i][0] = a[i][i] = 1;
for (int j = 1; j < i; j++)
a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j <= i; j++)
System.out.print(a[i][j] + " ");
System.out.println();
}
}
}