首页 > 试题广场 >

反序相等

[编程题]反序相等
  • 热度指数:13002 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
设N是一个四位数,它的9倍恰好是其反序数(例如:1234 的反序数是4321),求N的值。

输入描述:


输出描述:
每行一个数,表示满足题目要求的数。
示例1

输入

输出

头像 芙兰
发表于 2023-03-18 19:48:25
众所周知C++有许多好用又方便的库函数。to_string()可以把数字转成对应的字符串;reverse()函数可以实现字符串的快速翻转;stringstream 可以方便操作字符串并将其转成数字;然后……然后就没了(i的九倍也是四位数,i不能超过1111,可以缩短一点循环) #include &l 展开全文
头像 Luka_2001
发表于 2024-02-16 16:04:23
#include <iostream> #include<string> #include<algorithm> using namespace std; int reverse_(int x){ string str=to_string(x); 展开全文
头像 在考古的小鱼干很有气魄
发表于 2023-03-15 10:44:26
#include <bits/stdc++.h> using namespace std; string fun(int x){ string s = to_string(x); reverse(s.begin(),s.end()); return s; } int mai 展开全文
头像 牛客7777779号
发表于 2023-03-01 11:06:25
由于1111*9=9999,即N不会超过1111,所以循环只需要从1000~1111即可。 #include <iostream> using namespace std; int main() { int temp = 0; //存储反序数 for (int i = 展开全文
头像 bigbigcake
发表于 2024-03-12 14:08:15
#include <bits/stdc++.h> using namespace std; string f(int i){ i*=9; string s = to_string(i); reverse(s.begin(),s.end()); retur 展开全文
头像 给我就亿下
发表于 2023-03-26 14:21:42
#include <iostream> using namespace std; int reverse (int n){ int a = 0, b = 0; while (n != 0){ a = n % 10; n /= 10; b = b * 10 + a; 展开全文
头像 普罗列塔丽亚
发表于 2022-02-05 14:18:31
1111*9=9999 只需把范围缩小到1000到1111即可 #include<iostream> using namespace std; bool ok(int a){    &nbs 展开全文
头像 NaOH-j
发表于 2024-03-10 19:22:43
#include <iostream> #include <cstring> #include <sstream> #include <string> #include <algorithm> using namespa 展开全文