20-2 注意表示10的次方的思路别写成10*次方数
#include<iostream>
#include<queue>
using namespace std;
int n,a,b,cnt=0;
int reverse_num(int x)
{
queue<int> q;
while(x/10!=0)
{
q.push(x%10);
x=x/10;
}
q.push(x%10);
int sum=0,n=q.size();
while(!q.empty())
{
int m=1,i=n;
while(i>1)
{
m*=10;
i--;
}
sum+=m*q.front();
n--;
q.pop();
}
return sum;
}
int main()
{
cin>>n;
while(n--)
{
cin>>a>>b;
int a1=reverse_num(a);
int b1=reverse_num(b);
int sum1=reverse_num(a+b);
cout<<a<<'+'<<b<<'='<<a+b<<endl;
cout<<a1<<'+'<<b1<<'='<<a1+b1<<endl;
cout<<"a,b反序数的和"<<sum1<<endl;
if(a1+b1==sum1)
{
cnt++;
cout<<a<<" "<<b<<endl<<endl;
}
else cout<<"none"<<endl<<endl;
}
cout<<"符合条件的组数:"<<cnt<<endl;
return 0;
}
----------------------------------------
3
123 456
789 987
147 369
-------------------------------------------
123+456=579
321+654=975
a,b反序数的和975
123 456
789+987=1776
987+789=1776
a,b反序数的和6771
none
147+369=516
741+963=1704
a,b反序数的和615
none
符合条件的组数:1