思路:用字符串去处理最简单。注意边界int会炸。
code:
代码语言:javascript复制#include<bits/stdc .h>
using namespace std;
typedef long long ll;
ll tot;
int solve(string ss,int n,int l){
tot=0;
for(int i=0;i<l;i ){
if((ss[i]-'0') == n){
tot = n;
tot*=10;
}
}
return tot/10;
}
int main(){
string s1,s2;
int n1,n2;
cin>>s1>>n1>>s2>>n2;
int l1=s1.size();
int l2=s2.size();
// cout<<solve(s1,n1,l1)<<endl;
// cout<<solve(s2,n2,l2)<<endl;
cout<<solve(s1,n1,l1) solve(s2,n2,l2)<<endl;
return 0;
}