部分A+B (15) pow(x,y) x的y次方 A、DA、B、DB,A中DA出现的次数对应-》 1111 * 4=pa 求PA+PB

来源:互联网 发布:数据库表结设计例子 编辑:程序博客网 时间:2024/06/06 12:20
/*


正整数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 < 10^10。


输出格式:


在一行中输出PA + PB的值。


输入样例1:
3862767 6 13530293 3
输出样例1:
399
输入样例2:
3862767 1 13530293 8
*/




#include<iostream>
#include<string>


#include<math.h>   //x 的y次方  pow(x,y)
using namespace std;




int main()
{
string str1,str2;
int a,b;
int x=0,y=0;
cin>>str1>>a>>str2>>b;


for(int i=0;i<str1.length();i++) // string 字符串  长度yong str.length();
//注意 ()没写就会  有没有参数的错误
{
if(str1[i]-'0'==a){x++;}



}



for(int i=0;i<str2.length();i++)
{


   if(str2[i]-'0'==b)y++;

}


int temp=1;
if(x==0){temp=0;}
for(int i=2;i<=x;i++)
{
temp=temp+pow( 10,(i-1) );
}
temp=temp*a;
cout<<"x是"<<x<<"temp是"<<temp;







int tempy=1;
if(y==0){tempy=0;}
for(int i=2;i<=y;i++)
{
tempy=tempy+pow( 10,(i-1) );
}
tempy=tempy*b;
cout<<"y是"<<y<<"tempy是"<<tempy;


//cout<<temp*tempy;


cout<<"和是"<<temp+tempy;
return 0;

}



阅读全文
0 0
原创粉丝点击