50分求助

P1307 [NOIP2011 普及组] 数字反转

反转后开头和末尾的1也会掉><……
by NNFeNN @ 2023-05-30 20:50:22


不难吧
by Manipula @ 2023-05-30 20:51:40


```cpp #include <bits/stdc++.h> using namespace std; int main () { int n, m = 0; cin >> n; if (n < 0)cout << "-"; while (n != 0) { m = m * 10 + n % 10; n /= 10; } cout << m; return 0; } ```
by Manipula @ 2023-05-30 20:56:52


@[cc1if](/user/963247) 感谢……><
by NNFeNN @ 2023-05-31 19:42:54


```cpp #include <bits/stdc++.h> using namespace std; int main(){ int num; cin >> num; if(num == 0){ cout << 0; return 0; } if(num < 0){ cout << '-'; num = -num; } while(num % 10 == 0 && num > 0){ num = num / 10; } while(num > 0){ cout << num % 10; num = num / 10; } return 0; } ```
by Terry2011 @ 2023-06-01 16:55:09


|