PAT (Basic Level) Practise (中文) 1016. 部分A+B (15)
2017-08-30 14:40
405 查看
1016. 部分A+B (15)
时间限制100 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
正整数A的“DA(为1位整数)部分”定义为由A中所有DA组成的新整数PA。例如:给定A = 3862767,DA = 6,则A的“6部分”PA是66,因为A中有2个6。
现给定A、DA、B、DB,请编写程序计算PA + PB。
输入格式:
输入在一行中依次给出A、DA、B、DB,中间以空格分隔,其中0 < A, B < 1010。
输出格式:
在一行中输出PA + PB的值。
输入样例1:
3862767 6 13530293 3
输出样例1:
399
输入样例2:
3862767 1 13530293 8
输出样例2:
0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
//正整数 十的十次方 一百亿,超过整形范围
public class Main{
public static void main(String[] args) throws IOException {
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
String str=bf.readLine();
String arr[]=str.split(" ");
char[] str_a=arr[0].toCharArray();
int counter_a=0;
char[] str_b=arr[2].toCharArray();
int counter_b=0;
String _a="";
String _b="";
for (int i = 0; i < str_a.length; i++) {
if (str_a[i]==arr[1].toCharArray()[0]) {
counter_a++;
}
}
for (int i = 0; i < str_b.length; i++) {
if (str_b[i]==arr[3].toCharArray()[0]) {
counter_b++;
}
}
// for (int i = counter_a; i > 0; i--) {
// //先用字符串偷懒做
// }
for (int i = 0; i < counter_a; i++) {
_a+=arr[1];
}
for (int i = 0; i < counter_b; i++) {
_b+=arr[3];
}
// System.out.println(counter_a+" "+counter_b);
// System.out.println(_a+" "+_b);//偷懒可以做,这就方便了,不然还得套循环switch乘着加
int result;
try {
result=
a73a
Integer.parseInt(_a)+Integer.parseInt(_b);
} catch (Exception e) {
result=0;
}
System.out.println(result);
// boolean flag='c'=="c".toCharArray()[0];
// System.out.println(flag);//第一步先测试了字符串和字符怎么作比较
}
}
相关文章推荐
- PAT (Basic Level) Practise (中文)1016. 部分A+B (15)
- PAT (Basic Level) Practise (中文)- 1016. 部分A+B (15)
- PAT (Basic Level) Practise (中文)1016. 部分A+B (15)
- PAT (Basic Level) Practise (中文) 1016. 部分A+B (15)
- PAT (Basic Level) Practise (中文) 1061. 判断题(15)
- PAT (Basic Level) Practise (中文) 1051. 复数乘法 (15)
- PAT (Basic Level) Practise (中文)1001. 害死人不偿命的(3n+1)猜想 (15)
- PAT (Basic Level) Practise (中文)1061. 判断题(15)
- PAT (Basic Level) Practise (中文)1071. 小赌怡情(15)
- PAT (Basic Level) Practise (中文)1046. 划拳(15)
- PAT BASIC LEVEL 1016. 部分A+B (15)
- PAT (Basic Level) Practise (中文)- 1006. 换个格式输出整数 (15)
- PAT (Basic Level) Practise (中文)1036. 跟奥巴马一起编程(15)
- PAT (Basic Level) Practise (中文)1021. 个位数统计 (15)
- PAT (Basic Level) Practise (中文)1041. 考试座位号(15)
- PAT (Basic Level) Practise (中文)1006. 换个格式输出整数 (15) C语言
- PAT (Basic Level) Practise (中文)1011. A+B和C (15)
- PAT (Basic Level) Practise (中文)1041. 考试座位号(15) C语言
- PAT (Basic Level) Practise (中文)1021. 个位数统计 (15)
- PAT (Basic Level) Practise (中文) 1056. 组合数的和(15)