CCF CSP Brush Question Record 9-201509-1 Number Sequence Segmentation (java), 201509-2 Date Calculation (java)

Question number: 201509-1
Question name: Sequence segmentation
time limit: 1.0s
Memory limit: 256.0MB
Problem Description:

Problem Description

  Given a sequence of integers, the longest continuous sequence of integers in the sequence is counted as one segment. How many segments are there in the sequence?

Input format

  The first line of input contains an integer n , which represents the number of integers in the sequence.
  The second line contains n integers a 1,  a 2, …,  an , which represents a given sequence of numbers, and adjacent integers are separated by a space.

Output format

  Output an integer, indicating that the given sequence has multiple segments.

Sample input

8
8 8 8 0 12 12 8 0

Sample output

5

Sample description

  8 8 8 is the first paragraph, 0 is the second paragraph, 12 12 is the third paragraph, the penultimate integer 8 is the fourth paragraph, and the last 0 is the fifth paragraph.

Evaluation use case scale and conventions

  1 ≤  n  ≤ 1000,0 ≤  ai  ≤ 1000。

 

import java.util.Scanner; 
public class 数列分段 {

	public static void main(String[] args) {
		
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n];
		for(int i=0;i<n;i++){
			a[i]=sc.nextInt();
		}
		int res=0;
		for(int i=0;i<n-1;i++){
			if(a[i+1]!=a[i]){
				res++;
			}
		}
		System.out.println(res+1);
	}

}
Question number: 201509-2
Question name: Date calculation
time limit: 1.0s
Memory limit: 256.0MB
Problem Description:

Problem Description

  Given a year y and an integer d , asking the first year of the d -day is the day of the month?
  Note that there are 29 days in February in a leap year. A leap year is a leap year that meets one of the following conditions:
  1) The year is an integer multiple of 4 and not an integer multiple of 100;
  2) The year is an integer multiple of 400.

Input format

  输入的第一行包含一个整数y,表示年份,年份在1900到2015之间(包含1900和2015)。
  输入的第二行包含一个整数dd在1至365之间。

输出格式

  输出两行,每行一个整数,分别表示答案的月份和日期。

样例输入

2015
80

样例输出

3
21

样例输入

2000
40

样例输出

2
9

 

import java.util.Scanner; 
public class 日期计算 {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int y=sc.nextInt();
		int d=sc.nextInt();
		int total;
		if(d<=31){
			System.out.print("1"+"\n"+d+"\n");
		}else{
			if(y%400==0||(y%100!=0&&y%4==0)){
				if(d<=60){
					System.out.print("2"+"\n"+(d-31)+"\n");
				}else if(d<=91){
					System.out.print("3"+"\n"+(d-60)+"\n");
				}else if(d<=121){
					System.out.print("4"+"\n"+(d-91)+"\n");
				}else if(d<=152){
					System.out.print("5"+"\n"+(d-121)+"\n");
				}else if(d<=182){
					System.out.print("6"+"\n"+(d-152)+"\n");
				}else if(d<=213){
					System.out.print("7"+"\n"+(d-182)+"\n");
				}else if(d<=244){
					System.out.print("8"+"\n"+(d-213)+"\n");
				}else if(d<=274){
					System.out.print("9"+"\n"+(d-244)+"\n");
				}else if(d<=305){
					System.out.print("10"+"\n"+(d-274)+"\n");
				}else if(d<=335){
					System.out.print("11"+"\n"+(d-305)+"\n");
				}else if(d<=366){
					System.out.print("12"+"\n"+(d-335)+"\n");
				}
			}else{
				if(d<=59){
					System.out.print("2"+"\n"+(d-31)+"\n");
				}else if(d<=90){
					System.out.print("3"+"\n"+(d-59)+"\n");
				}else if(d<=120){
					System.out.print("4"+"\n"+(d-90)+"\n");
				}else if(d<=151){
					System.out.print("5"+"\n"+(d-120)+"\n");
				}else if(d<=181){
					System.out.print("6"+"\n"+(d-151)+"\n");
				}else if(d<=212){
					System.out.print("7"+"\n"+(d-181)+"\n");
				}else if(d<=243){
					System.out.print("8"+"\n"+(d-212)+"\n");
				}else if(d<=273){
					System.out.print("9"+"\n"+(d-243)+"\n");
				}else if(d<=304){
					System.out.print("10"+"\n"+(d-273)+"\n");
				}else if(d<=334){
					System.out.print("11"+"\n"+(d-304)+"\n");
				}else if(d<=365){
					System.out.print("12"+"\n"+(d-334)+"\n");
				}
			}
		}
		

	}

}

 

Guess you like

Origin blog.csdn.net/m0_37483148/article/details/108291056