L1- 017——024

L1-017到底有多二 (15 分)

一个整数“犯二的程度”定义为该数字中包含2的个数与其位数的比值。如果这个数是负数,则程度增加0.5倍;如果还是个偶数,则再增加1倍。例如数字-13142223336是个11位数,其中有3个2,并且是负数,也是偶数,则它的犯二程度计算为:3/11×1.5×2×100%,约为81.82%。本题就请你计算一个给定整数到底有多二。

输入格式:

输入第一行给出一个不超过50位的整数N

输出格式:

在一行中输出N犯二的程度,保留小数点后两位。

输入样例:

-13142223336

输出样例:

81.82%

注意下输出%是两个%%

代码

import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[]args)
	{
		String s = sc.next(); 
		double sum = 1;
		if(s.charAt(0) == '-')
		{
			sum = sum * 1.5;
			s = s.substring(1);
		}
		int len = s.length();
		if((s.charAt(len - 1) - '0') % 2 == 0)
			sum = sum * 2.0;
		double cnt = 0;
		for(int i = 0 ; i < len ; i ++)
		{
			if(s.charAt(i) == '2')
				cnt ++;
		}
		System.out.printf("%.2f%%",cnt / len * sum * 100 );
		
	}
}

L1-018 大笨钟 (10 分)

微博上有个自称“大笨钟V”的家伙,每天敲钟催促码农们爱惜身体早点睡觉。不过由于笨钟自己作息也不是很规律,所以敲钟并不定时。一般敲钟的点数是根据敲钟时间而定的,如果正好在某个整点敲,那么“当”数就等于那个整点数;如果过了整点,就敲下一个整点数。另外,虽然一天有24小时,钟却是只在后半天敲1~12下。例如在23:00敲钟,就是“当当当当当当当当当当当”,而到了23:01就会是“当当当当当当当当当当当当”。在午夜00:00到中午12:00期间(端点时间包括在内),笨钟是不敲的。

下面就请你写个程序,根据当前时间替大笨钟敲钟。

输入格式:

输入第一行按照hh:mm的格式给出当前时间。其中hh是小时,在00到23之间;mm是分钟,在00到59之间。

输出格式:

根据当前时间替大笨钟敲钟,即在一行中输出相应数量个Dang。如果不是敲钟期,则输出:

Only hh:mm.  Too early to Dang.

其中hh:mm是输入的时间。

输入样例1:

19:05

输出样例1:

DangDangDangDangDangDangDangDang

输入样例2:

07:05

输出样例2:

Only 07:05.  Too early to Dang.
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[]args)
	{
		String s = sc.next();
		int ss1 = Integer.parseInt(s.substring(0, 2));
		int ss2 = Integer.parseInt(s.substring(3));
		if(ss1 < 12 || ss1 == 12 && ss2 == 0)
			System.out.println("Only " + s +".  Too early to Dang.");
		else
		{
			int cnt = ss1 - 12 + (ss2 > 0 ? 1: 0);
			for(int i = 1; i <= cnt ; i ++)
				System.out.print("Dang");
			System.out.println();
		}
		
	}
}

 


L1-019 谁先倒 (15 分)

划拳是古老中国酒文化的一个有趣的组成部分。酒桌上两人划拳的方法为:每人口中喊出一个数字,同时用手比划出一个数字。如果谁比划出的数字正好等于两人喊出的数字之和,谁就输了,输家罚一杯酒。两人同赢或两人同输则继续下一轮,直到唯一的赢家出现。

下面给出甲、乙两人的酒量(最多能喝多少杯不倒)和划拳记录,请你判断两个人谁先倒。

输入格式:

输入第一行先后给出甲、乙两人的酒量(不超过100的非负整数),以空格分隔。下一行给出一个正整数N(≤100),随后N行,每行给出一轮划拳的记录,格式为:

甲喊 甲划 乙喊 乙划

其中是喊出的数字,是划出的数字,均为不超过100的正整数(两只手一起划)。

输出格式:

在第一行中输出先倒下的那个人:A代表甲,B代表乙。第二行中输出没倒的那个人喝了多少杯。题目保证有一个人倒下。注意程序处理到有人倒下就终止,后面的数据不必处理。

输入样例:

1 1
6
8 10 9 12
5 10 5 10
3 8 5 12
12 18 1 13
4 16 12 15
15 1 1 16

输出样例:

A
1
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[]args)
	{
		int anow = sc.nextInt();
		int bnow = sc.nextInt();
		int a = anow, b = bnow ;
		int n = sc.nextInt();
		for(int i = 1; i <= n; i ++)
		{
			int a1 = sc.nextInt();
			int a2 = sc.nextInt();
			int b1 = sc.nextInt();
			int b2 = sc.nextInt();
			if(a2 == a1 + b1)
				a --;
			if(b2 == a1 + b1)
				b--;
			if(a2 == a1 + b1 && b2 == a1 + b1)
			{
				a ++;
				b ++;
			}
			
			if(a < 0)
			{
				System.out.println("A");
				System.out.println(bnow - b);
				System.exit(0);
			}else if(b < 0)
			{
				System.out.println("B");
				System.out.println(anow - a);
				System.exit(0);
			}
		}
		
	}
}

L1-020 帅到没朋友 (20 分)

当芸芸众生忙着在朋友圈中发照片的时候,总有一些人因为太帅而没有朋友。本题就要求你找出那些帅到没有朋友的人。

输入格式:

输入第一行给出一个正整数N(≤100),是已知朋友圈的个数;随后N行,每行首先给出一个正整数K(≤1000),为朋友圈中的人数,然后列出一个朋友圈内的所有人——为方便起见,每人对应一个ID号,为5位数字(从00000到99999),ID间以空格分隔;之后给出一个正整数M(≤10000),为待查询的人数;随后一行中列出M个待查询的ID,以空格分隔。

注意:没有朋友的人可以是根本没安装“朋友圈”,也可以是只有自己一个人在朋友圈的人。虽然有个别自恋狂会自己把自己反复加进朋友圈,但题目保证所有K超过1的朋友圈里都至少有2个不同的人。

输出格式:

按输入的顺序输出那些帅到没朋友的人。ID间用1个空格分隔,行的首尾不得有多余空格。如果没有人太帅,则输出No one is handsome

注意:同一个人可以被查询多次,但只输出一次。

输入样例1:

3
3 11111 22222 55555
2 33333 44444
4 55555 66666 99999 77777
8
55555 44444 10000 88888 22222 11111 23333 88888

输出样例1:

10000 88888 23333

输入样例2:

3
3 11111 22222 55555
2 33333 44444
4 55555 66666 99999 77777
4
55555 44444 22222 11111

输出样例2:

No one is handsome
//运行超时

import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;
import java.util.Vector;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int pre[] = new int[100050];
	static int cnt[] = new int[100050];
	static int flag[] = new int[100050];
	public static void main(String[]args)
	{
		for(int i = 0; i <= 99999; i ++)
			pre[i] = i;
		Vector<Integer>vec = new Vector<Integer>();
		Set<Integer>st = new HashSet<Integer>();
		int n = sc.nextInt();
		while(n -- > 0)
		{
			int num = sc.nextInt();
			int kk = sc.nextInt();
			st.add(kk);
			for(int i = 2; i <= num; i ++)
			{
				int gg = sc.nextInt();
				merge(kk,gg);
				st.add(gg);
			}
		}
		
		n = sc.nextInt();
		for(int i = 0 ; i < n ; i ++)
		{
			int x = sc.nextInt();
			if(vec.contains(x) == false)
				vec.add(x);
		}
		
		
	
		Iterator<Integer> it = st.iterator();
		while(it.hasNext())
			cnt[find(it.next())] ++;
		Vector<Integer>out = new Vector<Integer>();
		for(int i = 0 ; i < vec.size(); i ++)
		{
			if(cnt[find(vec.get(i))] <= 1  )
				out.add(vec.get(i));
		}
		if(out.size() == 0)
			System.out.println("No one is handsome");
		else 
		{
			int size = out.size();
			for(int i = 0 ; i < size; i ++)
			{
				if(i != size - 1)
					System.out.printf("%05d ",out.get(i));
				else 
					System.out.printf("%05d\n",out.get(i));
			}
		}
		
	}
	private static void merge(int x, int y) {
		int fx = find(x);
		int fy = find(y);
		if(fx != fy)
			pre[fx] = fy;
		return;
	}
	private static int find(int x) {
		if(pre[x] == x)
			return x;
		else 
			return pre[x] = find(pre[x]);
	}
}
#include<bits/stdc++.h>
using namespace std;
int book[100005];
int gg[100005];
int main()
{
	int n,k,x;
	scanf("%d",&n);
	while(n--)
	{
		int k;
		scanf("%d",&k);
		for(int i=1;i<=k;i++){
			scanf("%d",&x);
			if(k>=2)book[x]=1;	
		}	
	}
	scanf("%d",&k);
	int flag=0; 
	for(int i=1;i<=k;i++){
		scanf("%d",&x);
		if(book[x]==0)
		{
			if(!flag&&gg[x]==0)
			{
				printf("%05d",x);
				flag=1;
				gg[x]++;
			}else if(flag==1&&gg[x]==0)
			{
				printf(" %05d",x);
				gg[x]++;
			}
		}	
	}
	if(!flag)printf("No one is handsome\n");
	return 0;
}

L1-021 重要的话说三遍 (5 分)

这道超级简单的题目没有任何输入。

你只需要把这句很重要的话 —— “I'm gonna WIN!”——连续输出三遍就可以了。

注意每遍占一行,除了每行的回车不能有任何多余字符。

输入样例:

输出样例:

I'm gonna WIN!
I'm gonna WIN!
I'm gonna WIN!
package vj;


import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;
import java.util.Vector;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[]args)
	{
		System.out.println("I'm gonna WIN!\nI'm gonna WIN!\nI'm gonna WIN!");
		
	}
}

L1-022 奇偶分家 (10 分)

给定N个正整数,请统计奇数和偶数各有多少个?

输入格式:

输入第一行给出一个正整N(≤1000);第2行给出N个非负整数,以空格分隔。

输出格式:

在一行中先后输出奇数的个数、偶数的个数。中间以1个空格分隔。

输入样例:

9
88 74 101 26 15 0 34 22 77

输出样例:

3 6
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;
import java.util.Vector;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[]args)
	{
		int n = sc.nextInt();
		int odd = 0 , even = 0;
		for(int i = 1; i <= n ; i ++)
		{
			int x = sc.nextInt();
			if(x % 2 == 0)
				even ++;
			else 
				odd ++;
		}
		System.out.println(odd +" " + even);
	}
}

L1-023 输出GPLT (20 分)

给定一个长度不超过10000的、仅由英文字母构成的字符串。请将字符重新调整顺序,按GPLTGPLT....这样的顺序输出,并忽略其它字符。当然,四种字符(不区分大小写)的个数不一定是一样多的,若某种字符已经输出完,则余下的字符仍按GPLT的顺序打印,直到所有字符都被输出。

输入格式:

输入在一行中给出一个长度不超过10000的、仅由英文字母构成的非空字符串。

输出格式:

在一行中按题目要求输出排序后的字符串。题目保证输出非空。

输入样例:

pcTclnGloRgLrtLhgljkLhGFauPewSKgt

输出样例:

GPLTGPLTGLTGLGLL

 

//老师挂的题里面是正确的 天梯里面运行超时?? 你逗我?


import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;
import java.util.Vector;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[]args)
	{
		String s = sc.next();
		s = s.toUpperCase();
		int []a = new int[10];
		for(int i = 0 ; i < s.length(); i ++)
		{
			if(s.charAt(i) == 'G') a[1]++;
			else if(s.charAt(i) == 'P') a[2]++;
			else if(s.charAt(i) == 'L') a[3]++;
			else if(s.charAt(i) == 'T') a[4]++;
		}
		char str[] = {'o','G','P','L','T'};
		int total = a[1] + a[2] + a[3] + a[4];
		while(total != 0)
		{
			for(int i = 1; i <= 4; i ++)
			{
				if(a[i] != 0)
				{
					System.out.print(str[i]);
					total --;
					a[i]--;
				}
			}
		}
		System.out.println();
	}
}

L1-024 后天 (5 分)

如果今天是星期三,后天就是星期五;如果今天是星期六,后天就是星期一。我们用数字1到7对应星期一到星期日。给定某一天,请你输出那天的“后天”是星期几。

输入格式:

输入第一行给出一个正整数D(1 ≤ D ≤ 7),代表星期里的某一天。

输出格式:

在一行中输出D天的后天是星期几。

输入样例:

3

输出样例:

5
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[]args)
	{
		int n = sc.nextInt();
		System.out.println((n + 2) % 7 == 0 ? 7 : (n + 2) % 7);
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值