题目 某君的年龄是个两位数,如果把他年龄的两位数字交换位置后与原数字相加和为 x,与原数字相减差的绝对值为 y。已知 x 比 y 大 32。请你计算 y 的值是多少
思路:暴力搜索
#include<iostream> #include<cmath> using namespace std; int main() { int x,y; for(int i = 10; i <= 99; i++) { int tmp = (i%10)*10+i/10; x = tmp+i; y = abs(tmp-i); if(x-32==y) { cout << y;//45 break; } } return 0; }
本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。
我来说两句