某君新认识一网友。
当问及年龄时,他的网友说:
“我的年龄是个2位数,我比儿子大27岁,
如果把我的年龄的两位数字交换位置,刚好就是我儿子的年龄”
请你计算:网友的年龄一共有多少种可能情况?
提示:30岁就是其中一种可能哦.
请填写表示可能情况的种数。
注意:你提交的应该是一个整数,不要填写任何多余的内容或说明性文字。
7
#include <iostream>
using namespace std;
#define MAX 100
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int count = 0;
int fage,sage;
int GetSonAge()
{
int a = fage;
int b = a%10;//个位
a /= 10; //十位
return b*10+a;
}
int main() {
for(int i = 27; i < MAX; i++)
{
fage = i;
sage = GetSonAge();
if(fage > sage && fage - sage == 27)
{
cout<<fage<<endl;
count++;
}
}
cout<<count<<endl;
return 0;
}