天梯赛练习集-L1-031到L1-040–python - java
文章目录
- Python
- L1-031 到底是不是太胖了
- L1-032 Left-pad
- L1-033 出生年
- L1-034 点赞
- L1-035 情人节
- L1-036 A乘以B
- L1-037 A除以B
- L1-038 新世界
- L1-039 古风排版
- L1-040 最佳情侣身高差
- Java
- L1-031 到底是不是太胖了
- L1-032 Left-pad
- L1-033 出生年
- L1-034 点赞
- L1-035 情人节
- L1-036 A乘以B
- L1-037 A除以B
- L1-038 新世界
- L1-039 古风排版
- L1-040 最佳情侣身高差
Python
L1-031 到底是不是太胖了
n = int(input())
for i in range(n):h,w = map(int,input().split())a = (h-100) * 1.8if abs(a - w) >= a *0.1:if a > w:print("You are tai shou le!")else:print("You are tai pang le!")else:print("You are wan mei!")
L1-032 Left-pad
a = input().split()
n = int(a[0])
c = a[1]
s = input()
l = len(s)
if l >= n:print(s[l-n:])
else:print(c*(n-l)+s)
L1-033 出生年
def check(a,b):s = set()for i in range(len(a)):s.add(a[i])if len(a) != 4:s.add('0')return b == len(s)a = input().split()
y = a[0]
year = int(y)
x = int(a[1])
i = 0
while True: if check(y,x):print(i,"%.4d" %int(y))breaki += 1y = str(year+i)
L1-034 点赞
n = int(input())
a = [0 for i in range(1001)]
maxvalue = 0
maxkey = 0
for i in range(n):s = list(map(int,input().split()))for j in range(1,len(s)):a[s[j]] += 1if a[s[j]] > maxvalue:maxvalue = a[s[j]]maxkey = s[j]if maxvalue == a[s[j]]:maxkey = max(maxkey,s[j])
print(maxkey,maxvalue)
L1-035 情人节
s=[]
n = input()
while n != ".":s.append(n)n = input()
if len(s) < 2:print("Momo... No one is for you ...")
elif len(s) < 14:print(s[1],"is the only one for you...")
else:print(s[1],"and",s[13],"are inviting you to dinner...")
L1-036 A乘以B
a,b = map(int,input().split())
print(a*b)
L1-037 A除以B
a,b = map(int,input().split())
if b == 0:c = "Error"
else:c = "%.2f" % (a/b)
if b < 0:print("%d/(%d)=" %(a,b),end='')
else:print("%d/%d=" %(a,b),end='')
print(c)
L1-038 新世界
print("""Hello World
Hello New World""")
L1-039 古风排版
n = int(input())
l = [[] for i in range(n)]
s = input()
j = 0
for i in s:l[j].append(i)j = (j + 1) % n
while j != 0:l[j].append(' ')j = (j + 1) % n
for i in l:print("".join(i[::-1]))
L1-040 最佳情侣身高差
n = int(input())
for i in range(n):a = input().split()sex = a[0]h = float(a[1])if sex == "M":print("%.2f" % (h/1.09))else:print("%.2f" % (h*1.09))
Java
L1-031 到底是不是太胖了
import java.io.*;public class Main {static final PrintWriter print = new PrintWriter(System.out);static final StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));public static int nextInt() throws IOException {st.nextToken();return (int) st.nval;}public static void main(String[] args) throws IOException {int n = nextInt();for (int i = 0; i < n; i++) {int h = nextInt();int w = nextInt();double a = (h - 100) * 1.8;if (Math.abs(a - w) >= a * 0.1) {if (a > w) {print.println("You are tai shou le!");} else {print.println("You are tai pang le!");}} else {print.println("You are wan mei!");}}print.flush();}
}
L1-032 Left-pad
import java.io.*;public class Main {static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));public static void main(String[] args) throws IOException {String[] s1 = br.readLine().split(" ");int l = Integer.parseInt(s1[0]);String c = s1[1];String s = br.readLine();if (s.length() > l) {System.out.println(s.substring(s.length() - l));}else{System.out.println(c.repeat(l - s.length()) + s);}}
}
L1-033 出生年
import java.io.*;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;public class Main {static final StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));public static int nextInt() throws IOException {st.nextToken();return (int) st.nval;}public static void main(String[] args) throws IOException {int year = nextInt();int copy = year;int num = nextInt();while (true){if (check(year,num)){System.out.printf("%d %04d\n",year - copy,year);break;}year++;}}private static boolean check(int year, int num) {int i = 0;Set<Integer> set = new HashSet<>();while (year > 0){set.add(year % 10);year /= 10;i++;}if (i != 4)set.add(0);return num==set.size();}
}
L1-034 点赞
map会超时
StreamTokenizer 的数字比readline的拆分要快。
printwriter没有必要。
BufferedReader超时
import java.io.*;public class Main {static final PrintWriter print = new PrintWriter(System.out);static final StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));public static int nextInt() throws IOException {st.nextToken();return (int) st.nval;}public static void main(String[] args) throws IOException {int n = nextInt();int max = 0;int[] arr = new int[1002];int maxKey = 0;for (int i = 0; i < n; i++) {int k = nextInt();for (int j = 0; j < k; j++) {int f = nextInt();arr[f]++;if (arr[f] > max){max = arr[f];maxKey = f;}else if (arr[f] == max){maxKey = Math.max(maxKey,f);}}}print.println(maxKey+" "+max);print.flush();}
}
L1-035 情人节
import java.io.*;
import java.util.ArrayList;public class Main {static final StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));public static String next() throws IOException {st.nextToken();return st.sval;}public static void main(String[] args) throws IOException {ArrayList<String> arr = new ArrayList<>();String s = next();while (s != null) {arr.add(s);s = next();}if (arr.size() < 2) {System.out.println("Momo... No one is for you ...");} else if (arr.size() < 14) {System.out.println(arr.get(1) + " is the only one for you...");} else {System.out.println(String.format("%s and %s are inviting you to dinner...", arr.get(1), arr.get(13)));}}}
L1-036 A乘以B
import java.io.*;public class Main {static final StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));public static int nextInt() throws IOException {st.nextToken();return (int) st.nval;}public static void main(String[] args) throws IOException {System.out.println(nextInt()*nextInt());}}
L1-037 A除以B
import java.io.*;public class Main {static final StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));public static int nextInt() throws IOException {st.nextToken();return (int) st.nval;}public static void main(String[] args) throws IOException {int a = nextInt();int b = nextInt();String c = b == 0 ? "Error" : String.format("%.2f", a * 1.0 / b);System.out.println(a + "/" + (b < 0 ? "(" + b + ")" : b)+"="+c);}
}
L1-038 新世界
import java.io.*;public class Main {public static void main(String[] args) throws IOException {System.out.println("Hello World");System.out.println("Hello New World");}
}
L1-039 古风排版
import java.io.*;public class Main {static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));public static void main(String[] args) throws IOException {int n = Integer.parseInt(br.readLine());char[] chars = br.readLine().toCharArray();StringBuilder[] ss = new StringBuilder[n];for (int i = 0; i < n; i++) {ss[i] = new StringBuilder();}int i = 0;for (char c : chars) {ss[i].append(c);i = (i + 1) % n;}if (i != 0) {while (i < n) {ss[i].append(' ');i++;}}for (StringBuilder s : ss) {System.out.println(s.reverse());}}
}
L1-040 最佳情侣身高差
import java.io.*;public class Main {static final StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));public static int nextInt() throws IOException {st.nextToken();return (int) st.nval;}public static String next() throws IOException {st.nextToken();return st.sval;}public static void main(String[] args) throws IOException {String man = "M";double rate = 1.09;int n = nextInt();for (int i = 0; i < n; i++) {String sex = next();st.nextToken();double h = st.nval;System.out.println(String.format("%.2f",man.equals(sex)?h/rate:h*rate));}}
}
天梯赛练习集-L1-031到L1-040–python - java相关推荐
- 【CCCC】PAT : 团体程序设计天梯赛-练习集 L1 答案
[CCCC]PAT : 团体程序设计天梯赛-练习集 L1 答案 鉴定完毕,全部水题 ヾ(•ω•`)o 标号 标题 分数 通过数 提交数 通过率 L1-001 Hello World 5 46779 1 ...
- 【CCCC】PAT : 团体程序设计天梯赛-练习集 L2 答案,题解,附代码
[CCCC]PAT : 团体程序设计天梯赛-练习集 L2 答案 鉴定完毕,全部水题 ヾ(•ω•`)o 知识点分类(32): 1.树锯结构(9):二叉树的存储,编号,遍历顺序转换,求深度,底层节点,从底 ...
- 团体程序设计天梯赛练习集题解整合
网上介绍 团体程序设计天梯赛练习集 的文章已经很多了, 我的这篇文章是对练习集题解的整合,方便每一位备战 团体程序设计天梯赛 的同学使用. 一年一度的 团体程序设计天梯赛 即将开始,PTA的练习集是必 ...
- 团体程序设计天梯赛-练习集 L1-033——L1-048
团体程序设计天梯赛-练习集 /** @Description: 出生年* @version: * @Author: * @Date: 2021-03-25 08:13:57* @LastEditors ...
- 【CCCC】PAT : 团体程序设计天梯赛-练习集 L3 答案(01-23)
[CCCC]PAT : 团体程序设计天梯赛-练习集 L3 答案 顶着满课,整整一星期,终于咕完了.(:´д`)ゞ 知识点分类(23): 1.搜索模拟(5):BFS,DFS,最短路,路径打印 2.计算几 ...
- PTA团体程序设计天梯赛-练习集(3)
PTA团体程序设计天梯赛-练习集 L1-001 Hello World (5 分) 这道超级简单的题目没有任何输入. 你只需要在一行中输出著名短句"Hello World!"就可以 ...
- PTA团体程序设计天梯赛-练习集
PTA团体程序设计天梯赛-练习集 L1-024 后天 L1-025 正整数A+B L1-026 I Love GPLT L1-027 出租 L1-029 是不是太胖了 L1-030 一帮一 L1-03 ...
- PTA团体程序设计天梯赛-练习集Level-1(参考代码C语言/Python版)
本题目集截止到2022年天梯赛 受个人水平限制,<PTA团体程序设计天梯赛-练习集>中暂时只能把Level-1的题目做出来(也许有些Level-2的题可以写出来?)-我不是专门搞竞赛的,参 ...
- 团体程序设计天梯赛-练习集(L1)
001:Hello World(5 分)(AC) 注意要点:无. #include<iostream> using namespace std;int main(){printf(&quo ...
- 『ACM C++』 PTA 天梯赛练习集L1 | 048-49
今日刷题048-049 ------------------------------------------------L1-048---------------------------------- ...
最新文章
- JS原生选项卡 – 幻灯片效果
- 原创 | 一文详解阿里云《人工智能红利渗透与爆发》技术趋势
- r语言的runmed函数_R实战 第五篇:常用函数的用法
- 发布md 的文章测试
- 如何把 .NET 进程中的所有托管异常找出来?
- linux方法参数,Linux的sysctl 命令 参数
- typora用Pandoc导出html,Typora安装 Pandoc实现导出功能
- windows动态库和静态库VS导入
- 中国互联网大佬隐退简史
- echart折线图删除_用Echart创建简单的折线图
- 深入biztalk消息以及消息订阅发布路由机制(四)-消息的轮询和执行
- POJ NOI0105-41 数字统计
- python如何检查错误-python中的错误如何查看
- 关于OpenCV使用遇到的问题集(多数为转载)
- python复习第一节
- Excel进行描述性统计分析
- 如何获取网页logo与favicon图标使用
- 检测局域网内在线IP
- 计算机专业相关的组名和口号,课堂小组霸气组名和口号大全
- 树莓派声音输出设置_树莓派3 之 音响配置
热门文章
- python诞生的时间地点人物事件_Python学习之四大名著人物出场次数Python代码
- Windows下postgresql安装步骤(超级详细)
- 好像绝大部分是政府和企事业单位
- AutoCAD中扩展图元数据的应用
- 四合一图床上传-高速Cdn图床百度/新浪/360/搜狗图床
- unity防御游戏《超级英雄大战僵尸》截图
- [附源码]Python计算机毕业设计SSM机械零件生产管理系统(程序+LW)
- Xcode 6 技巧: 矢量图像,代码片段以及其他
- net, 哥已心灰意冷
- Java MorseCoder - Java 语言实现的摩尔斯电码编码解码器