天梯赛每日打卡02(7-12题解)
Posted Huterox
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了天梯赛每日打卡02(7-12题解)相关的知识,希望对你有一定的参考价值。
文章目录
- 前言
- L1-012 计算指数 (5 分)
- L1-010 比较大小 (10 分)
- L1-007 念数字 (10 分)
- L1-008 求整数段和 (10 分)
- L1-009 N个数求和 (20 分)
- L1-011 A-B (20 分)
前言
由于上课这个效率慢了一点儿,后面还有一篇关于YoloV1论文解读的博文~
打卡第二天
L1-012 计算指数 (5 分)
送分分
import java.util.Scanner;
public class Main
public static void main(String[] args)
Scanner scanner = new Scanner(System.in);
int nextInt = scanner.nextInt();
scanner.close();
System.out.println("2^"+nextInt+" = "+(1<<nextInt));
就喜欢做 level 1 嘿嘿~
L1-010 比较大小 (10 分)
import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main
public static void main(String[] args) throws IOException
Scanner scanner = new Scanner(new BufferedInputStream(System.in));
ArrayList<Integer> res = new ArrayList<>();
for (int i = 0; i < 3; i++)
res.add(scanner.nextInt());
scanner.close();
res.sort((a,b)->
return a-b;
);
System.out.print(res.get(0)+"->"+res.get(1)+"->"+res.get(2));
L1-007 念数字 (10 分)
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main
//0: ling
//1: yi
//2: er
//3: san
//4: si
//5: wu
//6: liu
//7: qi
//8: ba
//9: jiu
static HashMap<Character,String> Mapping = new HashMap<>();
static
Mapping.put('0',"ling");
Mapping.put('1',"yi");
Mapping.put('2',"er");
Mapping.put('3',"san");
Mapping.put('4',"si");
Mapping.put('5',"wu");
Mapping.put('6',"liu");
Mapping.put('7',"qi");
Mapping.put('8',"ba");
Mapping.put('9',"jiu");
Mapping.put('-',"fu");
public static void main(String[] args)
Scanner scanner = new Scanner(System.in);
String numbers = scanner.next();
scanner.close();
int size = numbers.toCharArray().length;
char[] numbers_char=numbers.toCharArray();
for (int i = 0; i < size; i++)
if(i==size-1)
System.out.printf("%s", Mapping.get(numbers_char[i]));
else
System.out.printf("%s ", Mapping.get(numbers_char[i]));
L1-008 求整数段和 (10 分)
这题很简单,注意输出格式呀
import java.util.Scanner;
public class Main
public static void main(String[] args)
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int m = scan.nextInt();
int sum=0;
int count=0;
for(int i=n;i<=m;i++)
System.out.printf("%5d",i);
count++;
sum=sum+i;
if(count%5==0&&i!=m)
System.out.println();
System.out.printf("\\nSum = %d",sum);
L1-009 N个数求和 (20 分)
这题的话就是注意使用gcd就行了,求最小公倍数,然后注意输出格式
import java.io.BufferedInputStream;
import java.util.Scanner;
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));
in.readLine();
String[]strings=in.readLine().split(" ");
String[]s=strings[0].split("/");
long a=Long.parseLong(s[0]);
long b=Long.parseLong(s[1]);
long gg=gcd(a, b);
a/=gg;
b/=gg;
for (int i = 1; i < strings.length; i++)
s=strings[i].split("/");
long c=Long.parseLong(s[0]);
long d=Long.parseLong(s[1]);
a=a*d+c*b;
b*=d;
gg=gcd(a, b);
a/=gg;
b/=gg;
if(a/b==0&&a%b!=0)
System.out.print(a+"/"+b);
else if(a/b!=0&&a%b==0)
System.out.print(a/b);
else if(a/b!=0&&a%b!=0)
System.out.print(a/b+" "+a%b+"/"+b);
else
System.out.print(0);
in.close();
private static long gcd(long a,long b)
if (a<0)
a=-a;
if (b<0)
b=-b;
return b==0?a:gcd(b, a%b);
L1-011 A-B (20 分)
这题我想锤人,可能是平台有问题。
同一个代码,一次14 一次 17 神马毛病?
import java.util.Scanner;
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 b=in.readLine();
char[] bs=b.toCharArray();
String news=s;
for (int i = 0; i < b.length(); i++)
String c = String.valueOf(bs[i]);
news=news.replace(c, "");
System.out.println(news);
然后用Python直接过,我不理解
a=input()
b=list(input())
for i in b:
a=a.replace(i,"")
print(a)
以上是关于天梯赛每日打卡02(7-12题解)的主要内容,如果未能解决你的问题,请参考以下文章