pat(B)1016. 部分A+B

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#define LL long long
using namespace std;

int main()
{
	LL a,b;
	LL c,d;
	LL f[15];
	f[0]=1;
	int i;
	for(i=1;i<15;i++)
	{
		f[i]=f[i-1]*10;
	}
	while(scanf("%lld%lld%lld%lld",&a,&c,&b,&d)!=EOF)
	{
		LL aa=0,bb=0;
		while(a>0)
		{
			int r=a%10;
			if(r==c)
				aa++;
			a=a/10;
		}
		a=0;
		while(aa>0)
		{
			a+=c*f[aa-1];
			aa--;
		}
		while(b>0)
		{
			int r=b%10;
			if(r==d)
				bb++;
			b=b/10;
		}
		b=0;
		while(bb>0)
		{
			b+=d*f[bb-1];
			bb--;
		}
		printf("%lld\n",a+b);
	}
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-18 06:35:33

pat(B)1016. 部分A+B的相关文章

PAT乙级 1016. 部分A+B (15)

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

pat甲级1016

1016 Phone Bills (25)(25 分) A long-distance telephone company charges its customers by the following rules: Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts conn

PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)

1016 Phone Bills (25 分)   A long-distance telephone company charges its customers by the following rules: Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connec

PAT:1016. 部分A+B (15) AC

当做字符串处理#include<stdio.h> #include<string.h> int main() { char A[120],B[120],ca,cb; int iA=0,iB=0; scanf("%s %c %s %c",A,&ca,B,&cb); int lenA=strlen(A),lenB=strlen(B); int addA=0,addB=0; while(lenA!=-1) //遍历每一位,是目标数就处理 { int t

PAT(A) 1016. Phone Bills (25)

A long-distance telephone company charges its customers by the following rules: Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connecting a long-distance call,

PAT 乙级 1016

1 #include <iostream> 2 #include <cmath> 3 using namespace std; 4 5 int main() { 6 int a = 0, da = 0; 7 int b = 0, db = 0; 8 cin >> a >> da >> b >> db; 9 int cnta = 0, cntb = 0; 10 int chu = a, yu = 0; 11 while (chu >

PAT乙级1016.部分A+B(15 分)

正整数 A 的“D?A??(为 1 位整数)部分”定义为由 A 中所有 D?A?? 组成的新整数 P?A??.例如:给定 8,D?A??=6,则 A 的“6 部分”P?A?? 是 66,因为 A 中有 2 个 6. 现给定 A.D?A??.B.D?B??,请编写程序计算 P?A??+P?B??. 输入格式: 输入在一行中依次给出 A.D?A??.B.D?B??,中间以空格分隔,其中 0. 输出格式: 在一行中输出 P?A??+P?B?? 的值. 输入样例 1: 3862767 6 1353029

PAT 1016. Phone Bills

PAT 1016. Phone Bills A long-distance telephone company charges its customers by the following rules: Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connecting

PAT 乙级真题 1006.1016.部分A+B

PAT 乙级真题 1006.1016.部分A+B 题目描述 正整数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的值. 输入样例 386276

1016. Phone Bills (25)——PAT (Advanced Level) Practise

题目信息: 1016. Phone Bills (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A long-distance telephone company charges its customers by the following rules: Making a long-distance call costs a certain amount per minute, depending