1016 部分A+B (15 分)
正整数 A 的“DA(为 1 位整数)部分”定义为由 A 中所有 DA 组成的新整数 PA。例如:给定 8,DA=6,则 A 的“6 部分”PA 是 66,因为 A 中有 2 个 6。
现给定 A、DA、B、DB,请编写程序计算 PA+PB。
输入格式:
输入在一行中依次给出 A、DA、B、DB,中间以空格分隔,其中 0。
输出格式:
在一行中输出 PA+PB 的值。
输入样例 1:
3862767 6 13530293 3
输出样例 1:
399
输入样例 2:
3862767 1 13530293 8
输出样例 2:
0
注意判断先后顺序(别用Scanner):
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.nio.Buffer;
import java.util.*;
public class Main{ public static void main(String[] args) throws IOException { //Scanner scanner = new Scanner(System.in);
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); String []str=bf.readLine().split(" ");
// int a=Integer.parseInt(str[1]);
// int b=Integer.parseInt(str[3]);
if(str[0].contains(str[1])==false||str[2].contains(str[3])==false){
System.out.println(0);
return;
} StringBuilder ra= new StringBuilder("");
StringBuilder rb= new StringBuilder("");
for(int i=0;i<str[0].length();i++){
if(str[1].equals(str[0].charAt(i)+"")){
ra.append(str[1]);
}
}
for(int i=0;i<str[2].length();i++){
if(str[3].equals(str[2].charAt(i)+"")){
rb.append(str[3]);
}
}
// if(ra.length()==0||rb.length()==0){
// System.out.println(0);
// return;
// } BigInteger a1 = new BigInteger(ra.toString());
BigInteger b1 = new BigInteger(rb.toString());
System.out.println(a1.add(b1)); }
}
ReaderBuffer为什么比Scanner快:https://blog.csdn.net/linxdcn/article/details/72886231
1016 部分A+B (15 分)的更多相关文章
- PAT Basic 1016 部分A+B (15 分)
正整数 A 的“DA(为 1 位整数)部分”定义为由 A 中所有 DA 组成的新整数 PA.例如:给定 8,DA=6,则 A 的“6 部分”PA 是 66,因为 A 中有 ...
- PAT (Basic Level) Practice (中文)1016 部分A+B (15 分)
正整数 A 的“DA(为 1 位整数)部分”定义为由 A 中所有 DA 组成的新整数 PA.例如:给定 8,DA=6,则 A 的“6 部分”PA 是 66,因为 A 中有 ...
- PTA | 1016 部分A+B (15分)
正整数 A 的"DA(为 1 位整数)部分"定义为由 A 中所有 DA 组成的新整数 PA.例如:给定 A=3862767,DA=6,则 A 的"6 部分"PA ...
- [刷题] 1016 部分A+B (15分)
思路 以字符串形式接收 遍历字符串,组装数据,输出结果 #include <iostream> using namespace std; int main() { string a, b; ...
- 【PAT】1016 部分A+B(15 分)
1016 部分A+B(15 分) 正整数 A 的“DA(为 1 位整数)部分”定义为由 A 中所有 DA 组成的新整数 PA.例如:给定 A=3862767,DA=6,则 A ...
- 1016 Phone Bills (25 分)
1016 Phone Bills (25 分) A long-distance telephone company charges its customers by the following rul ...
- PAT乙级 1016. 部分A+B (15) C语言实现
1016. 部分A+B (15) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 正整数A的“DA(为1位整数)部 ...
- PAT-乙级-1016. 部分A+B (15)
1016. 部分A+B (15) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 正整数A的“DA(为1位整数)部 ...
- PAT (Basic Level) Practise (中文) 1016. 部分A+B (15)
1016. 部分A+B (15) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 正整数A的"DA(为1 ...
随机推荐
- Plastic Bottle Manufacturer: Characteristic Analysis Of Plastic Packaging Bottles
Plastic packaging bottles are usually made of 7 materials. Due to its inherent characteristics, the ...
- acm数论之旅(转载) -- 逆元
ACM数论之旅6---数论倒数,又称逆元(我整个人都倒了( ̄﹏ ̄)) 数论倒数,又称逆元(因为我说习惯逆元了,下面我都说逆元) 数论中的倒数是有特别的意义滴 你以为a的倒数在数论中还是1/a吗 ( ...
- 吴裕雄 PYTHON 神经网络——TENSORFLOW 无监督学习处理MNIST手写数字数据集
# 导入模块 import numpy as np import tensorflow as tf import matplotlib.pyplot as plt # 加载数据 from tensor ...
- 时间同步服务器ntpd的搭建
如果系统没有默认安装,可以手动安装,一条命令就可以搞定: yum install ntp -y 安装之后修改配置文件: vim /etc/ntp.conf #restrict 127.0.0.1 #r ...
- 一个HTTP数据包的奇幻之旅
我是一个HTTP数据包,不知谁创建了我,把我丢到这个房间. 突然,来了一个大汉,我吓得缩到角落. “该启程了,站起来”. “去哪里啊?” 我弱弱的问. “还能去哪里,你是一个数据包,当然要出远门,完成 ...
- js中substr、substring、indexOf、lastIndexOf的用法
substr substr(start,length)表示从start位置开始,截取length长度的字符串 var str="imgs/header_2.jpg"; consol ...
- HDU4280 Island Transport
ISAP求最大流模板 #include<cstdio> #include<cstring> #include<algorithm> #include<iost ...
- 吴裕雄 python 神经网络——TensorFlow 图像处理函数
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt image_raw_data = tf.gfile ...
- 显ipQQ
链接:https://pan.baidu.com/s/1l1WN4b3jT8n4e66DH8d-cg 提取码:kjm4
- STM32cubeMX安装FW_F4容易出错失败的解决办法
在CUBEMXV5.30安装F4的支持包V1.241的反复失败,无法自动生成代码.后来发现了一种办法: 在stm32的官网下载V1.24.0和en.patch_cubefw_f4.zip(V1.24. ...