题目一:
反序数_牛客题霸_牛客网 (nowcoder.com)https://www.nowcoder.com/practice/e0d06e79efa44785be5b2ec6e66ba898?tpId=60&tqId=31035&tPage=2&ru=/kaoyan/retest/1001&qru=/ta/tsing-kaoyan/question-ranking
#include<iostream>
using namespace std;//设N是一个四位数,它的9倍恰好是其反序数(例如:1234的反序数是4321)
//求N的值int Reverse(int i)
{int remain = 0;int rev = 0;while (1){rev = rev * 10 + remain;remain = i % 10;if (i == 0){break;}i = i / 10;}return rev;
}
int main()
{for (int i = 1000; i <= 9999; i++){int rev = Reverse(i);if (rev == i * 9){cout << i << endl;}}return 0;
}
题目二:
对称平方数1_牛客题霸_牛客网 (nowcoder.com)https://www.nowcoder.com/practice/a84d46d5321f4e20931cb725e6c74fad?tpId=60&tqId=31036&tPage=2&ru=%2Fkaoyan%2Fretest%2F1001&qru=%2Fta%2Ftsing-kaoyan%2Fquestion-ranking
#include<iostream>
using namespace std;//描述:
//打印所有不超过256,其平方具有对称性质的数。如2,11就是这样的数,因为2 * 2 = 4,11 * 11 = 121。
//输入描述:
//无任何输入数据
//输出描述:
//输出具有题目要求的性质的数。如果输出数据不止一组,各组数据之间以回车隔开。
int Reverse(int u)
{int remain = 0;int rev = 0;while (1){rev = rev * 10 + remain;remain = u % 10;if (u == 0){break;}u = u / 10;}return rev;
}
int main()
{for (int i = 0; i <= 256; i++){int u = i * i;int rev = Reverse(u);if (u == rev){cout << i << endl;}}return 0;
}
题目三:
与7无关的数_牛客题霸_牛客网 (nowcoder.com)https://www.nowcoder.com/practice/776d401bf86d446fa783f0bef7d3c096?tpId=61&tqId=29522&tPage=2&ru=/kaoyan/retest/1002&qru=/ta/pku-kaoyan/question-ranking
#include<iostream>
using namespace std;
//一个正整数,如果它能被7整除,或者它的十进制表示法中某个位数上的数字为7,
//则称其为与7相关的数.现求所有小于等于n(n<100)的与7无关的正整数的平方和。//对于每个测试案例输出一行,输出小于等于n的与7无关的正整数的平方和。bool IsASeneven(int i)
{while (i){if (i % 10 == 7){return true;}i = i / 10;}return false;
}
int main()
{int n = 0;while (cin >> n){int sum = 0;for (int i = 0; i <= n; i++){if (i % 7 == 0 || IsASeneven(i)){continue;//与7相关的数字}sum += i * i;}cout << sum << endl;}return 0;
}
题目四:
3377. 约数的个数 - AcWing题库https://www.acwing.com/problem/content/3380/
#include <iostream>
using namespace std;
int main() {int n;int a; // 用来保存每个aicin >> n;for (int i = 0; i < n; ++i) {cin >> a;int count = 0; // count用来统计约数的个数for (int j = 1; j*j <= a; ++j) {// j用来试探是否是ai的约数// 设ai = p * q , 则 p和q的较小值必然小于ai的平方根// 而且 p 和 q 必然成对出现,p是约数,对应的q = ai/p 也必是约数 if (j * j == a) {++count; // ai是完全平方数,此时pq相同}else if (a % j == 0) {count += 2;}}cout << count << endl;}return 0;
}
解法二:利用set的去重特性来解题
#include<iostream>
#include<set>
using namespace std;int main()
{int n;cin >> n;while (n){set<int> s;int x;cin >> x;for (int i = 1; i*i <= x; i++){if (x % i == 0)//如果能够整除说明是约数{//利用s的去重特性s.insert(i);//每次插入小的is.insert(x / i);//再插入可以整除的那个大的数}}cout << s.size() << endl;s.clear();//每次记得将s清空再统计n--;}return 0;
}
题目五:
3644. 水仙花数 - AcWing题库https://www.acwing.com/problem/content/3647/
#include<iostream>
using namespace std;bool IsA(int x1)
{int x = x1;int remain = 0;int sum = 0;while (1){remain = x1 % 10;sum += remain * remain*remain;if (x1 == 0){break;}x1 = x1 / 10;}if (sum == x){return true;}else{return false;}
}
int main()
{int x1, x2;while (1){cin >> x1;cin >> x2;if (x1 == 0 && x2 == 0){break;}int flag = 0;for (int i = x1; i <= x2; i++){bool a = IsA(i);if (a){flag = 1;cout << i << " ";}}if (flag == 0){cout << "no" << endl;}else{cout << endl;}}return 0;
}
题目六:
Old Bill_牛客题霸_牛客网 (nowcoder.com)https://www.nowcoder.com/practice/17a30153e092493e8b4d13f321343927?tpId=40&tqId=21426&tPage=1&rp=1&ru=/ta/kaoyan&qru=/ta/kaoyan/question-ranking
#include<iostream>
using namespace std;int main()
{int n;cin >> n;int x1, x2, x3;cin >> x1 >> x2 >> x3;int sum = 0;for (int i = 1; i <= 9; i++){for (int j = 0; j <= 9; j++){int data = i * 10000 + x1 * 1000 + x2 * 100 + x3 * 10 + j;if (data % n == 0 && data >= sum){sum = data;}}}int c1, c2;c1= sum / 10000;c2 = sum % 10;if (c1 == 0 && c2 == 0 && sum == 0)cout << 0 << endl;elsecout << c1 << " " << c2 << " " << sum / n << endl;return 0;
}
题目七:
xxx定律_牛客题霸_牛客网 (nowcoder.com)https://www.nowcoder.com/practice/75c189249d6145cfa33cd53edae6afc8?tpId=63&tqId=29579&tPage=1&ru=/kaoyan/retest/9001&qru=/ta/zju-kaoyan/question-ranking
#include<iostream>
using namespace std;int main()
{//对于一个数n,如果是偶数,就把n砍掉一半;//如果是奇数,把n变成 3*n+ 1后砍掉一半,直到该数变为1为止。//请计算需要经过几步才能将n变到。int n;cin >> n;int count = 0;while (1){if (n == 1){break;}if (n % 2 == 0){//说明是偶数n = n / 2;}else{//说明是奇数n = 3 * n + 1;n = n / 2;}count++;}cout << count << endl;return 0;
}
题目八:
3390. 特殊乘法 - AcWing题库https://www.acwing.com/problem/content/3393/
#include<iostream>
#include<vector>
using namespace std;int main()
{int a, b;cin >> a >> b;vector<int> v1;vector<int> v2;while (1){v1.push_back(a % 10);if (a == 0){break;}a = a / 10;}while (1){v2.push_back(b % 10);if (b == 0){break;}b = b / 10;}int sum = 0;for (int i = 0; i < v1.size(); i++){for (int j = 0; j < v2.size(); j++){sum += v1[i] * v2[j];}}cout << sum << endl;return 0;
}