- 前言
- L1-014 简单题 (5 分)
- L1-021 重要的话说三遍 (5 分)
- L1-024 后天 (5 分)
- L1-022 奇偶分家 (10 分)
- L1-013 计算阶乘和 (10 分)
- L1-018 大笨钟 (10 分)
- L1-015 跟奥巴马一起画方块 (15 分)
- L1-016 查验身份z (15 分)
- L1-025 正整数A+B (15 分)
- L1-019 谁先倒 (15 分)
- L1-020 帅到没朋友 (20 分)
- L1-023 输出GPLT (20 分)
- 总结
打卡第三天,今天水课比较多,多刷几个题目,看看下个礼拜能不能刷到level 2。
目前来看除了那个连续因子的题目,我觉得很有意思,其他的还没遇到更好玩的.
今天做的题目还是简单的,但是那些格式,和输入数据的细节真的是,不跑不知道,一跑吓一跳。
还是按照难易排序。
稍晚一点还有一篇关于从0开始制作自己的分类“框架”。
只要是模仿yolo的工程的基本结构,玩玩儿~
L1-014 简单题 (5 分)
public class Main {
public static void main(String[] args) {
System.out.println("This is a simple problem.");
}
}
L1-021 重要的话说三遍 (5 分)
public class Main {
//先水几题
public static void main(String[] args) {
for (int i = 0; i < 3; i++) {
System.out.println("I'm gonna WIN!");
}
}
}
L1-024 后天 (5 分)
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int a[]= {1,2,3,4,5,6,7};
int b[]= {3,4,5,6,7,1,2};
Scanner sc = new Scanner(System.in);
int D = sc.nextInt();
if(D<=7){
System.out.println(b[D-1]);
}
}
}
L1-022 奇偶分家 (10 分)
import java.io.BufferedInputStream;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int count_j = 0;
int count_o = 0;
Scanner scanner = new Scanner(new BufferedInputStream(System.in));
int N = scanner.nextInt();
for (int i = 0; i < N; i++) {
if(scanner.nextInt()%2==0){
count_o++;
}else {
count_j++;
}
}
System.out.println(count_j+" "+count_o);
}
}
L1-013 计算阶乘和 (10 分)
暴力直接过
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner std=new Scanner(System.in);
int N=std.nextInt();
int Sum=0,num=1;
for(int i=1;i<=N;i++) {
//计算第i个数的阶乘
num=num*i;
//求阶乘和
Sum+=num;
}
System.out.println(Sum);
}
}
L1-018 大笨钟 (10 分)
这个题目注意细节,注意输入。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String time = scanner.next();
String[] times = time.split(":");
int H = Integer.parseInt(times[0]);
int M = Integer.parseInt(times[1]);
if(H>12&&M>0){
int D = (H-11);
while (D-->0){
System.out.print("Dang");
}
}else if(H>12 && M==0){
int D = (H-12);
while (D-->0){
System.out.print("Dang");
}
}
else {
System.out.println("Only "+time+". Too early to Dang.");
}
}
}
L1-015 跟奥巴马一起画方块 (15 分)
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
String str=scan.next();
int a=0;
if(n%2==0)
{
a=n/2;
}
else
{
a=n/2+1; //四舍五入取整
}
for (int i=0;i<a;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(str);
}
System.out.println();
}
scan.close();
}
}
L1-016 查验身份z (15 分)
这个也很简单,map即可
import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
//这里就不用map了,用两个列表映射一下就行了
public static void main(String[] args) {
Scanner scanner = new Scanner(new BufferedInputStream(System.in));
ArrayList<String> res = new ArrayList<>();
char[] chars = { '1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2' };
int[] index = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };
int n = scanner.nextInt();
String[] str = new String[n];
char[][] c = new char[n][18];
for (int i = 0; i < n; i++) {
str[i] = scanner.next();
c[i] = str[i].toCharArray();
int sum = 0;
for (int j = 0; j < 17; j++) {
try {
sum += Integer.parseInt((c[i][j] + "")) * index[j];
} catch (Exception e) {
sum = -1;
break;
}
}
if (sum == -1) {
res.add(str[i]);
} else {
sum %= 11;
if (!(chars[sum] + "").equals((c[i][17]) + "")) {
res.add(str[i]);
}
}
}
if (res.isEmpty()) {
System.out.print("All passed");
} else {
for (String ss : res) {
System.out.println(ss);
}
}
}
}
L1-025 正整数A+B (15 分)
这题一定要注意输入细节
尤其是这样的输入:
12 58 sadawda
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
//细节怪
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String s = in.readLine();
String r1 = s.substring(0, s.indexOf(' '));
String r2 = s.substring(s.indexOf(' ') + 1, s.length());
String s1 = "", s2 = "", s3 = "";
int n1 = 0, n2 = 0;
try {
int x1 = Integer.parseInt(r1);
if (x1 < 1 || x1 > 1000) {
s1 = "?";
s3 = "?";
}
n1 = x1;
} catch (NumberFormatException e) {
s1 = "?";
s3 = "?";
}
try {
int x2 = Integer.parseInt(r2);
if (x2 < 1 || x2 > 1000) {
s2 = "?";
s3 = "?";
}
n2 = x2;
} catch (NumberFormatException e) {
s2 = "?";
s3 = "?";
}
System.out.print(s1.equals("") ? n1 + " + " : s1 + " + ");
System.out.print(s2.equals("") ? n2 + " = " : s2 + " = ");
System.out.println(s3.equals("") ? n1 + n2 : s3);
}
}
L1-019 谁先倒 (15 分)
这题咋说呢,都被给的测试集骗了
注意细节
import java.io.BufferedInputStream;
import java.util.Scanner;
import java.util.Scanner;
public class Main {
//不能边来边判断,不然找不到的,那个测试集误导人!!
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = 0, b = 0;// 甲乙酒量
int N = 0;// 划拳轮数
a = sc.nextInt();
b = sc.nextInt();
N = sc.nextInt();
int sum;
int A_current_drink = 0, B_current_drink = 0;
boolean flagA = false, flagB = false;
int[][] drinking = new int[N][4];
//初始化
for (int i = 0; i < N; i++) {
for (int j = 0; j < 4; j++) {
drinking[i][j] = sc.nextInt();
}
}
for (int i = 0; i < N; i++) {
sum = drinking[i][0] + drinking[i][2];
if (sum == drinking[i][1] && sum != drinking[i][3]) {
A_current_drink++;
if (A_current_drink > a) {
flagA = true;
break;
}
}
if (sum == drinking[i][3] && sum != drinking[i][1]) {
B_current_drink++;
if (B_current_drink > b) {
flagB = true;
break;
}
}
}
if (flagA) {
System.out.println("A");
System.out.println(B_current_drink);
}
if (flagB) {
System.out.println("B");
System.out.println(A_current_drink);
}
}
}
L1-020 帅到没朋友 (20 分)
题目非常骚气,描述的情况简直和我一毛一样!
我是用java写的,死活没法全过。
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int count=0;
int id=0;
int i=0;
Set<Integer> set = new HashSet<>();
for (i = 0; i <n ; i++) {
int m = scanner.nextInt();
for (int j = 0; j < m; j++) {
id=scanner.nextInt();
if (m!=1){
set.add(id); //只有朋友圈人数大于1才默认其有朋友
}
}
}
int num = scanner.nextInt();
for (i = 0; i <num ; i++) {
int new_id = scanner.nextInt();
//如果出现的ID不存在Set集合中,说明没有朋友
//避免重复的输出,将其加入Set集合中,
if (set.add(new_id)){
//输出的打印格式
if (count==0){
System.out.printf("%05d",new_id);//不足五位自动补零
}else {
System.out.printf(" %05d",new_id);
}
count++;
}
}
if (count==0){
System.out.println("No one is handsome");
}else{
System.out.println();
}
}
}
L1-023 输出GPLT (20 分)
这个题目的思路也简单,用哈希大法。
但是死活过不了,java的。
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int count=0;
int id=0;
int i=0;
Set<Integer> set = new HashSet<>();
for (i = 0; i <n ; i++) {
int m = scanner.nextInt();
for (int j = 0; j < m; j++) {
id=scanner.nextInt();
if (m!=1){
set.add(id); //只有朋友圈人数大于1才默认其有朋友
}
}
}
int num = scanner.nextInt();
for (i = 0; i <num ; i++) {
int new_id = scanner.nextInt();
//如果出现的ID不存在Set集合中,说明没有朋友
//避免重复的输出,将其加入Set集合中,
if (set.add(new_id)){
//输出的打印格式
if (count==0){
System.out.printf("%05d",new_id);//不足五位自动补零
}else {
System.out.printf(" %05d",new_id);
}
count++;
}
}
if (count==0){
System.out.println("No one is handsome");
}else{
System.out.println();
}
}
}
总结
今天就先这样吧,脸黑~
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)