CCF比赛

试题编号: 201612-1
试题名称: 中间数
时间限制: 1.0s
内存限制: 256.0MB
问题描述:
问题描述
  在一个整数序列a 1, a 2, …, a n中,如果存在某个数,大于它的整数数量等于小于它的整数数量,则称其为中间数。在一个序列中,可能存在多个下标不相同的中间数,这些中间数的值是相同的。
  给定一个整数序列,请找出这个整数序列的中间数的值。
输入格式
  输入的第一行包含了一个整数n,表示整数序列中数的个数。
  第二行包含n个正整数,依次表示a 1, a 2, …, a n
输出格式
  如果约定序列的中间数存在,则输出中间数的值,否则输出-1表示不存在中间数。
样例输入
6
2 6 5 6 3 5
样例输出
5
样例说明
  比5小的数有2个,比5大的数也有2个。
样例输入
4
3 4 6 7
样例输出
-1
样例说明
  在序列中的4个数都不满足中间数的定义。
样例输入
5
3 4 6 6 7
样例输出
-1
样例说明
  在序列中的5个数都不满足中间数的定义。
评测用例规模与约定
  对于所有评测用例,1 ≤ n ≤ 1000,1 ≤ a i ≤ 1000。
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner c =new Scanner(System.in);
		int num[]=new int[1001];
		int n=c.nextInt();
		for(int i=0;i<n;i++){
			++num[c.nextInt()];
		}
		int count=0;
		boolean flag=true;
		for(int i=1;i<1001;i++){
			int ss=num[i];
			
			if(ss!=0 &&count==n-count-ss){
				flag =false;
				System.out.println(i);break;
			}else count+=ss;			
		}
		if(flag)System.out.println(-1);
	}

}

 结果:





 

试题编号: 201612-2
试题名称: 工资计算
时间限制: 1.0s
内存限制: 256.0MB
问题描述:
问题描述
  小明的公司每个月给小明发工资,而小明拿到的工资为交完个人所得税之后的工资。假设他一个月的税前工资(扣除五险一金后、未扣税前的工资)为S元,则他应交的个人所得税按如下公式计算:
  1) 个人所得税起征点为3500元,若S不超过3500,则不交税,3500元以上的部分才计算个人所得税,令A=S-3500元;
  2) A中不超过1500元的部分,税率3%;
  3) A中超过1500元未超过4500元的部分,税率10%;
  4) A中超过4500元未超过9000元的部分,税率20%;
  5) A中超过9000元未超过35000元的部分,税率25%;
  6) A中超过35000元未超过55000元的部分,税率30%;
  7) A中超过55000元未超过80000元的部分,税率35%;
  8) A中超过80000元的部分,税率45%;
  例如,如果小明的税前工资为10000元,则A=10000-3500=6500元,其中不超过1500元部分应缴税1500×3%=45元,超过1500元不超过4500元部分应缴税(4500-1500)×10%=300元,超过4500元部分应缴税(6500-4500)×20%=400元。总共缴税745元,税后所得为9255元。
  已知小明这个月税后所得为T元,请问他的税前工资S是多少元。
输入格式
  输入的第一行包含一个整数T,表示小明的税后所得。所有评测数据保证小明的税前工资为一个整百的数。
输出格式
  输出一个整数S,表示小明的税前工资。
样例输入
9255
样例输出
10000
评测用例规模与约定
  对于所有评测用例,1 ≤ T ≤ 100000。

 程序:

import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner c= new Scanner(System.in);
		double mony=c.nextDouble();
		if(mony<=3500)System.out.println((int)mony);
		else if(mony>3500 && mony<=4955){
			System.out.println(getMony(mony,3500,0.97)+3500);
		}else if(mony>4955 && mony<=7655){			
			System.out.println(3500+1500+getMony(mony,4955,0.9));
		}else if(mony>7655 && mony<=11255){
			System.out.println(3500+4500+getMony(mony,7655,0.8));
		} else if(mony>11255 && mony<=30755){
			System.out.println(3500+9000+getMony(mony,11255,0.75));
		}else if(mony>30755 && mony<=44755){		
			System.out.println(3500+35000+getMony(mony,30755,0.7));
		}else if(mony>44755 && mony<61005){
			System.out.println(3500+55000+getMony(mony,44755,0.65));
		}else{
			System.out.println(3500+80000+getMony(mony,61005,0.55));
		}		
	}
	public static int getMony(double mony,int tem,double rate){
		mony=mony-tem;
		mony=mony/rate;
		return (int)Math.ceil(mony); //取上整
	}
}

 

 

package com;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.util.Scanner;
public class C2016123 {
	public static void main(String[] args) {
		List<String> authority = new ArrayList<String>();
		List<List<String>> role = new ArrayList<List<String>>();//角色权限
		List<List<String>> userRole =new ArrayList<List<String>>();
		List<List<String>> selectRole = new ArrayList<List<String>>();
		List<List<String>> userAuthor = new ArrayList<List<String>>();
		Scanner c= new Scanner(System.in);
		int AuthNum=c.nextInt();
		for(int i=0;i<AuthNum;i++){
			authority.add(c.next()); // 权限
		}
		int roleNum=c.nextInt();
		c.nextLine();
		for(int i=0;i<roleNum;i++){  //角色权限
			String str= c.nextLine();
			String ro[]=str.split(" ");
			List<String> tem= new ArrayList<String>();
			for(int j=0;j<ro.length;j++){
				tem.add(ro[j]);
			}
			tem.remove(1);
			role.add(tem);
		}
		int user=c.nextInt();
		c.nextLine();
		for(int i=0;i<user;i++){
			String str = c.nextLine(); //用户角色
			String u[] =str.split(" ");
			List<String> tem= new ArrayList<String>();
			for(int j=0;j<u.length;j++){
				tem.add(u[j]);
			}
			tem.remove(1);
			userRole.add(tem);
		}
		for(int i=0;i<userRole.size();i++){
			String usernameI = userRole.get(i).get(0);
			List<String> userAuthI= new ArrayList<String>();
			userAuthI.add(usernameI);
			ListIterator<String> rrs=userRole.get(i).listIterator(1);
			while(rrs.hasNext()){
				String roleII=rrs.next();
				for(int j=0;j<role.size();j++){
					List<String> auths= role.get(j);
					if(roleII!=null &&roleII.equals(auths.get(0))){
						ListIterator<String> authors= role.get(j).listIterator(1);
						while(authors.hasNext()){
							String auorit=authors.next();
							userAuthI.add(auorit);
							//userAuthI.addAll((Collection<? extends String>) authors);
						}
					}
				}
			}
			userAuthor.add(userAuthI);
		}
		int select =c.nextInt(); //查询
		c.nextLine();
		for(int i=0;i<select;i++){
			String str =c.nextLine();
			String sel[]=str.split(" ");
			List<String> tem= new ArrayList<String>();
			for(int j=0;j<sel.length;j++){
				tem.add(sel[j]);
			}
			selectRole.add(tem);
		}
		for(int i=0;i<select;i++){
			String selctName=selectRole.get(i).get(0);
			String selctAuthority=selectRole.get(i).get(1);
			boolean falgName=false;
			for(int j=0;j<userAuthor.size();j++){
				boolean flag=false;
				if(selctName.equals(userAuthor.get(j).get(0))){
					falgName=true; //查询的用户存在
					ListIterator<String> allAuthor=userAuthor.get(j).listIterator(1);
					int preRank=-10;
					while(allAuthor.hasNext()){
						String authorII=allAuthor.next();
						if(selctAuthority.contains(":")){
							String rankAuthor=selctAuthority.split(":")[0];
							int  rank=Integer.parseInt(selctAuthority.split(":")[1]);
							String allAuthor1 = authorII.split(":")[0];
							int allrank = Integer.parseInt(authorII.split(":")[1]);
							if(rankAuthor.equals(allAuthor1) && allrank>=rank){
								System.out.println("true");
								flag=true;
								break;
							}
						}else{
							if(authorII.contains(":") && authorII.split(":")[0].equals(selctAuthority) 
									&& preRank<Integer.parseInt(authorII.split(":")[1])){								
								preRank = Integer.parseInt(authorII.split(":")[1]);								
								flag=true;								
							}else if(selctAuthority.equals(authorII) && !authorII.contains(":")){
								flag=true;
								System.out.println("true");
							}
						}
					}
					if(preRank>-10){
						System.out.println(preRank);
					}				
					if(!flag){ //判断是权限不存在还是未定义
						
						System.out.println("false"); //用户不具有该权限
					}
				}
			}
			if(!falgName){
				System.out.println("false"); 
			}		
		}
	}
}

 

猜你喜欢

转载自435727748.iteye.com/blog/2359799