当前位置: 首页 > news >正文

PAT(最近)

1022 D进制的A+B - PAT (Basic Level) Practice (中文)

加减位置调换

本来以为就是简单的 十进制转换为一个长的字符串 没想到在那个拼接字符串的时候 只需要简单的 加减位置调换就可以 避免使用麻烦的翻转函数

import java.util.Scanner;
public class twenty_two {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int a = scanner.nextInt();int b = scanner.nextInt();int d = scanner.nextInt();int c=a+b;String ll="";while(c>0){int cour=c%d;ll=cour+ll;  
// 方法一 真的是 想出来这个方法的真的是天才 
//因为字符串可以与整数通过相加而拼接 所以我只需要 
//调整cour这个余数加在ll的前面即可 
//可能是因为整数加多了下意识的就是ll+=courc=c/d;}
//下面则是我的方法 再次引入一个翻转函数StringBuffer 总而言之不如他的StringBuffer re=new StringBuffer(ll);System.out.println(re.reverse());
}
}

1037 在霍格沃茨找零钱 - PAT (Basic Level) Practice (中文)

“.”不可以直接用 . 分割

它的意思是任意字符的意思  需要使用"\\." 

import java.util.Scanner;
public class thirty_seven {
public static void main(String[] args) {Scanner myin = new Scanner(System.in);String l=myin.nextLine();String PA[]=l.split(" ");//注意如果使用 "."分割时候必须加上"\\." //因为单个 . 代表任意字符 不可行String P1[]=PA[0].split("\\.");String A2[]=PA[1].split("\\.");int a=0,b=0;a=Integer.parseInt(P1[0])*17*29+Integer.parseInt(P1[1])*29+Integer.parseInt(P1[2]);b=Integer.parseInt(A2[0])*17*29+Integer.parseInt(A2[1])*29+Integer.parseInt(A2[2]);    int ans=Math.abs(a-b);//System.out.println(ans);int cou[]= new int[3];cou[0]=ans/17/29;cou[1]=(ans-cou[0]*17*29)/29;cou[2]=ans-cou[0]*17*29-cou[1]*29;if(a>b){System.out.print("-");}for (int i = 0; i < 3; i++) {System.out.print(cou[i]);if(i!=2){System.out.print(".");}}
}
}

 

 

相关文章:

  • 商汤科技前端面试题及参考答案
  • 如何避免项目结束后知识流失
  • 【基础知识】常见公式计算(三)
  • 【论文阅读】Harnessing the Power of LLM to Support Binary Taint Analysis
  • 汽车服务小程序功能点开发
  • 密码学基石:哈希、对称/非对称加密与HTTPS实践详解
  • 世界无人机大会将至,大势智慧以“AI+实景三维”赋能低空经济
  • TypeScript类型挑战-刷题
  • 适合java程序员的Kafka消息中间件实战
  • Kafka生产者send方法详解
  • phpstudy升级新版apache
  • 加速项目落地(Trae编辑器)
  • 《Overlapping Experiment Infrastructure: More, Better, Faster》论文阅读笔记
  • 剑指大规模 AI 可观测,阿里云 Prometheus 2.0 应运而生
  • 支持向量机
  • 【Linux 系统调试】Linux 调试工具strip使用方法
  • View的事件分发机制
  • BBDM学习笔记
  • spring的事件监听
  • 计操第四章存储管理
  • 退休夫妻月入1.2万负债1.2亿申请破产,律师:“诚实而不幸”系前置条件
  • 中美经贸高层会谈11日在日内瓦将继续进行
  • 著名蒙古族音乐学者马•斯尔古愣逝世,享年86岁
  • 乘客被地铁厕所门砸伤,南京地铁:突然坏的,已和乘客沟通处理
  • 开局良好,我国第一季度广告业务收入保持较快增速
  • 逆境之上,万物生长