5 条题解
-
2
第一次写题解。。
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; while (n % 10 == 0) // 去除n末尾的0(们) n /= 10; if (n > 0) //判断正负数 如果为正数 { while (n > 0) //分离数位 反向输出 { cout << n % 10; // 求n的个位 n /= 10; // 将n整体右移一位(舍去已经输出的个位) } } else // 如果为负数 { n = abs(n); // 求绝对值(现去除负号) cout << "-"; // 补上负号 while (n > 0) // 分离数位 * 2(同10-14行) { cout << n % 10; n /= 10; } } }
-
1
#include<bits/stdc++.h> using namespace std; char n[11],c[11]; int q=0; int main() { cin>>n; int len = strlen(n); for(int i=len-1,j=0;i>=0;i--,j++) c[j]=n[i];// 赋值在c字符串上 for(int i=0;i<len;i++){// 枚举起点 if(c[i]!='0') break;// 不为0时退出 else q++;// 为0是起点向后调 } len=strlen(c); int f=0; if(c[len-1]=='-'){ cout<<'-'; f=1;// 如果有负号把末尾的负号去掉 } for(int i=q;i<len-f;i++) cout<<c[i]; return 0; }
字符串果然是个好东西👀️
- 1
信息
- ID
- 185
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 6
- 标签
- 递交数
- 251
- 已通过
- 83
- 上传者