码农知识堂 - 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. }

  • 相关阅读:
    环形链表问题(判环、求入口点)
    股票买卖Ⅴ
    重新认识受控和非受控组件
    艾美捷ProSci丨ProSci HIV-1 p24 抗体解决方案
    [安卓APP毕业设计源码]基于Uniapp实现的医生诊疗APP
    volatile关键字理解
    springcloud之项目实战搭建单体
    OpenNebula的配置与应用(一)
    关卡一: jQuery编程
    Nginx跨域防盗链搭建3台Tomcat集群
  • 原文地址:https://blog.csdn.net/weixin_61639349/article/details/127706096
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号