1016部分A+B
2015-11-03 21:11
363 查看
正整数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:
输出样例1:
输入样例2:
输出样例2:
0
现给定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
#include<iostream> #include<string> #include<math.h> using namespace std; //string add(string str1,string str2){ // reverse(str1.begin(),str1.end()); // reverse(str2.begin(),str2.end()); // if(str1.length() < str2.length()){ // int carry = 0; // for(int i = 0;i < str1.length();i++){ // if() // } // } //} int main(){ string str_A,str_B; char a,b; for(;cin>>str_A>>a>>str_B>>b;){ int count_A = 0,count_B = 0; for(int i =0;i < str_A.length();i++){ if(str_A[i] == a){ count_A++; } } for(int j =0;j < str_B.length();j++){ if(str_B[j] == b){ count_B++; } } long long int sum = 0; for(int i = 0;i<count_A;i++){ sum+= pow(10,i)*(a - '0'); } for(int i = 0;i < count_B;i++){ sum+= pow(10,i)*(b - '0'); } cout<<sum<<endl; } return 0 ; }
相关文章推荐
- SUMO使用教程(七)
- AngularJS API之toJson 对象转为JSON
- Lua1.0 代码分析 table.c
- vbs自学(一)
- RPC(Remote procedure call)
- Html+Css详解Css选择器,优先级与匹配原理
- 没有躲过的坑--deprecated关键字
- 读取写入SharedPreferences数据
- 简易QQ登录实现账号密码保存
- 没有躲过的坑--deprecated关键字
- [NOIP 2011]铺地毯 模拟
- opencv打开图片用到的ShowImage()函数和ResizeImage()函数
- SUMO使用教程(六)
- PyQt4(简单布局)
- python 2.7疑难问题之 编码
- Android面试总结2
- cf(思维题,判断两个大数的大小的比较方法)
- leetcode-Minimum Window Substring
- 使用系统类NSURLSessionDownloadTask实现断点续传(音乐视频下载等)
- C/C++基本数据类型大小及表示范围