码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 【PTA-训练day4】L2-015 互评成绩 + L1-011 A-B


    目录

    L2-015 互评成绩 - 简单模拟排序

    1、java版 - 超时

     2、c++版

    L1-016 查验身份证 - 15

    L1-013 计算阶乘和 - 10

    L1-011 A-B - 20

    1、c++版

    2、java版 - 超时


    L2-015 互评成绩 - 简单模拟排序

    PTA | 程序设计类实验辅助教学平台

    1、java版 - 超时

    java喜闻乐见的传统节目——运行超时

    思路没问题 我觉得打比赛还是用c++吧……

    1. import java.util.*;
    2. public class Main
    3. {
    4. public static void main(String[] args)
    5. {
    6. Scanner sc=new Scanner(System.in);
    7. int n=sc.nextInt(),k=sc.nextInt(),m=sc.nextInt();
    8. int[] res=new int[n];
    9. for(int i=0;i
    10. {
    11. int maxx=-1,minx=101,sum=0;
    12. for(int j=0;j
    13. {
    14. int x=sc.nextInt();
    15. maxx=Math.max(maxx,x);
    16. minx=Math.min(minx,x);
    17. sum+=x;
    18. }
    19. sum=sum-maxx-minx;
    20. res[i]=sum;
    21. }
    22. Arrays.sort(res);
    23. for(int i=n-m;i
    24. {
    25. if(i!=n-m) System.out.print(" ");
    26. System.out.printf("%.3f",res[i]*1.0/(k-2));
    27. }
    28. }
    29. }

     2、c++版

    1. #include
    2. using namespace std;
    3. int main()
    4. {
    5. int n,k,m;
    6. cin>>n>>k>>m;
    7. int res[n];
    8. for(int i=0;i
    9. {
    10. int maxx=-1,minx=101,sum=0;
    11. for(int j=0;j
    12. {
    13. int x;
    14. cin>>x;
    15. maxx=max(maxx,x);
    16. minx=min(minx,x);
    17. sum+=x;
    18. }
    19. sum-=maxx+minx;
    20. res[i]=sum;
    21. }
    22. sort(res,res+n);
    23. for(int i=n-m;i
    24. {
    25. if(i!=n-m) cout<<" ";
    26. printf("%.3f",res[i]*1.0/(k-2));
    27. }
    28. }

    L1-016 查验身份证 - 15

    PTA | 程序设计类实验辅助教学平台

    1. import java.util.*;
    2. public class Main
    3. {
    4. public static void main(String[] args)
    5. {
    6. Scanner sc=new Scanner(System.in);
    7. int[] w={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
    8. char[] ck={'1','0','X','9','8','7','6','5','4','3','2'};
    9. int n=sc.nextInt();
    10. int cnt=0;
    11. while(n-->0)
    12. {
    13. String s=sc.next();
    14. int sum=0;
    15. for(int i=0;i<17;i++) sum+=w[i]*(s.charAt(i)-'0');
    16. char t=ck[sum%=11];
    17. if(t==s.charAt(17)) continue;
    18. cnt++;
    19. System.out.println(s);
    20. }
    21. if(cnt==0) System.out.print("All passed");
    22. }
    23. }

    L1-013 计算阶乘和 - 10

    PTA | 程序设计类实验辅助教学平台

    1. import java.util.*;
    2. public class Main
    3. {
    4. public static void main(String[] args)
    5. {
    6. Scanner sc=new Scanner(System.in);
    7. int n=sc.nextInt();
    8. int sum=0;
    9. for(int i=1;i<=n;i++)
    10. {
    11. int t=1;
    12. for(int j=1;j<=i;j++)
    13. t*=j;
    14. sum+=t;
    15. }
    16. System.out.print(sum);
    17. }
    18. }

     

    L1-011 A-B - 20

    PTA | 程序设计类实验辅助教学平台

    1、c++版

    • cin        //遇到空白(包括回车、空格等)结束输入
    • getline(cin,str)     //可以输入一行,能接收空格
    1. #include
    2. using namespace std;
    3. int main()
    4. {
    5. string s,str;
    6. getline(cin,s);
    7. getline(cin,str);
    8. set<char>st;
    9. for(auto x:str) st.insert(x);
    10. for(auto x:s)
    11. {
    12. if(st.count(x)) continue;
    13. cout<
    14. }
    15. }

    2、java版 - 超时

    这题喜闻乐见的用Java超时 无语

    1. import java.util.*;
    2. public class Main
    3. {
    4. public static void main(String[] args)
    5. {
    6. Scanner sc=new Scanner(System.in);
    7. String s=sc.nextLine();
    8. String str=sc.nextLine();
    9. Set st=new HashSet<>();
    10. for(int i=0;i
    11. for(int i=0;i
    12. {
    13. if(st.contains(s.charAt(i))) continue;
    14. System.out.print(s.charAt(i));
    15. }
    16. }
    17. }

  • 相关阅读:
    HarmonyOS 学习记录
    图像显示在对话框上的一些问题
    常见代码优化技术
    CubeMX+VSCode+Ozone的STM32开发工作流(二)VSCode环境配置
    马赛克战对指挥与通信领域的启示分析
    (55、56)性能分析命令
    fatal: not in a git directory Error: Command failed with exit 128: git
    C++Prime Plus(7)
    C#WPF文本转语音实例
    MySQL 空间碎片详解
  • 原文地址:https://blog.csdn.net/weixin_61639349/article/details/127706096
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号