l_k_ @ 2024-10-24 00:31:06
#include <stdio.h>
int main() {
char c[30];
char ch;
int i=0;
while((ch=getchar())!='\n') {
c[i]=ch;
i++;
}
int t=i-1;
if(!t) printf("%c",c[0]);
for(i=t;i>=1;i--) {
if (i==t &&c[0]=='-') putchar(c[0]);
if (i==t) {
while (c[i]=='0') i--;
}
putchar(c[i]);
if(1==i && c[0]!='-') putchar(c[0]);
}
return 0;
}
by Coder_Tianyu @ 2024-10-24 07:30:11
用reverse函数吧,入门题目刷了就行。
#include <bits/stdc++.h>
std::string m;
int main() {
std::getline(std::cin, m);
while(m[m.size() - 1] == '0' && m.size() != 1 + (m[0] == '-'))
m.erase(m.size() - 1);
reverse(m.begin() + (m[0] == '-'), m.end()), printf("%s", m.c_str()), exit(0);
}
by yzy18635593659 @ 2024-11-09 21:02:42
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
bool flag=0;
cin>>s;
if(s=="0")
{
cout<<0;
return 0;
}
if(s[0]=='-')cout<<'-';
else s='-'+s;
for(int i=s.size()-1;s[i]!='-';i--)
{
if(s[i]>'0')flag=1;
if(flag)cout<<s[i];
}
}
AC代码 求关
by l_k_ @ 2024-11-11 15:59:51
@Coder_Tianyu 感谢大佬
by l_k_ @ 2024-11-11 16:00:18
@yzy18635593659 感谢感谢
by l_k_ @ 2024-11-11 16:01:40
这个代码在0测试点RE的原因是,0这个测试点没有回车,所以程序结束不了,应改为!=EOF