网友年龄
网友年龄
某君新认识一网友。
当问及年龄时,他的网友说:
“我的年龄是个2位数,我比儿子大27岁,
如果把我的年龄的两位数字交换位置,刚好就是我儿子的年龄”
请你计算:网友的年龄一共有多少种可能情况?
提示:30岁就是其中一种可能哦.
请填写表示可能情况的种数。
注意:你提交的应该是一个整数,不要填写任何多余的内容或说明性文字。
解析
C++代码
1 #include <bits/stdc++.h>
2 using namespace std;
3
4 bool check(int x) {
5 int y = x - 27;
6 int xx = x%10 * 10 + x/10;
7 if(xx == y) return true;
8 return false;
9 }
10
11 int main() {
12 int cnt = 0;
13 for(int i=10; i<=99; ++i)
14 if(check(i)) {
15 printf("%d\n", i);
16 cnt ++;
17 }
18 cout << cnt << endl;
19 return 0;
20 }