CCF CSP刷题记录7——201412-1门禁系统(Java) 、201503-1图像旋转(Java)

试题编号: 201412-1
试题名称: 门禁系统
时间限制: 1.0s
内存限制: 256.0MB
问题描述:

问题描述

  涛涛最近要负责图书馆的管理工作,需要记录下每天读者的到访情况。每位读者有一个编号,每条记录用读者的编号来表示。给出读者的来访记录,请问每一条记录中的读者是第几次出现。

输入格式

  输入的第一行包含一个整数n,表示涛涛的记录条数。
  第二行包含n个整数,依次表示涛涛的记录中每位读者的编号。

输出格式

  输出一行,包含n个整数,由空格分隔,依次表示每条记录中的读者编号是第几次出现。

样例输入

5
1 2 1 1 3

样例输出

1 1 2 3 1

评测用例规模与约定

  1≤n≤1,000,读者的编号为不超过n的正整数。

import java.util.Scanner; 
public class 门禁系统201412_1 {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int total=sc.nextInt();
		int[] a=new int[1001];
		int[] res=new int[total+1];
		for(int i=1;i<=total;i++){
			int per=sc.nextInt();
			a[per]+=1;
			res[i]=a[per];
			
		}
		for(int i=1;i<=total;i++){
			System.out.print(res[i]+" "); 
		}
		System.out.println();
	}

}
试题编号: 201503-1
试题名称: 图像旋转
时间限制: 5.0s
内存限制: 256.0MB
问题描述:

问题描述

  旋转是图像处理的基本操作,在这个问题中,你需要将一个图像逆时针旋转90度。
  计算机中的图像表示可以用一个矩阵来表示,为了旋转一个图像,只需要将对应的矩阵旋转即可。

输入格式

  输入的第一行包含两个整数nm,分别表示图像矩阵的行数和列数。
  接下来n行每行包含m个整数,表示输入的图像。

输出格式

  输出m行,每行包含n个整数,表示原始矩阵逆时针旋转90度后的矩阵。

样例输入

2 3
1 5 3
3 2 4

样例输出

3 4
5 2
1 3

评测用例规模与约定

  1 ≤ n≤ 1,000,矩阵中的数都是不超过1000的非负整数。

我的内存超范围了 只有90分 等刷到100分我再更新代码

import java.util.Scanner; 
public class 图像旋转201503_1 {

	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];
//		for(int i=1;i<=n;i++){
//			for(int j=1;j<=m;j++){
//				a[i][j]=sc.nextInt();
//			}
//		}
//		for(int j=m;j>=1;j--){
//			for(int i=1;i<=n;i++){
//				System.out.print(a[i][j]+" ");
//			}
//			System.out.println();
//		}
	
		int[] a=new int[n*m+1];
		for(int i=1;i<=n*m;i++){
				a[i]=sc.nextInt();
		}
		for(int j=0;j<m;j++){
			for(int i=1;i<=n;i++){
				System.out.print(a[m*i-j]+" ");
			}
			System.out.println();
		}
//		long memory =Runtime.getRuntime().totalMemory();
//		System.out.println(memory);
	}
}

猜你喜欢

转载自blog.csdn.net/m0_37483148/article/details/108288103