PAT (Basic Level) Practice (中文)1016 部分A+B
https://pintia.cn/problem-sets/994805260223102976/problems/994805306310115328
分析
判断某数字的个数 并形成某数字个数的的新数字
这里我就取余求每一位 然后初始化是 目标数 所以结果对多一个数字 最后删去一位就好了
wa了一次 就是没注意 是A>0 所以可能是long
代码
package PAT.BasicLevel;
import java.util.Scanner;
public class _1016_部分AaddB {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
long a = cin.nextLong(), a1 = cin.nextInt(), b = cin.nextInt(), b1 = cin.nextInt();
long t1=a1;
long t2=b1;
while (a != 0) {
long x = a % 10;
if (x == t1) {
a1 *= 10;
a1 += x;
}
a/=10;
}
while (b != 0) {
long x = b % 10;
if (x == t2) {
b1 *= 10;
b1 += x;
}
b/=10;
}
System.out.println(a1/10+b1/10);
}
}
本文作者:Author: 寒光博客
文章标题:[PAT] 1016 部分A+B
本文地址:https://dxoca.cn/pat/273.html 百度已收录
版权说明:若无注明,本文皆为“Dxoca's blog (寒光博客)”原创,转载请保留文章出处。
本文地址:https://dxoca.cn/pat/273.html 百度已收录
版权说明:若无注明,本文皆为“Dxoca's blog (寒光博客)”原创,转载请保留文章出处。