HuangZihan181 @ 2024-08-22 11:22:13
#include<bits/stdc++.h>
using namespace std;
string n,ans;
int a;
int main(){
cin>>n;
int l=n.length()-1;
if(n[0]=='-'){
a=1;
cout<<'-';
}
for(int i=l-1,j=0;i>=a;i--,j++){
ans=ans+n[i];
}
if(ans[0]=='0'){
ans.erase(0,ans.find_first_not_of('0'));
}
cout<<ans;
return 0;
}
by 违规用户名K&xs3Z^ @ 2024-08-22 11:24:15
@HuangZihan181 其实 想得简单一些呢(?
#include<bits/stdc++.h>
using namespace std;
long long n,ans;
int main(){
cin>>n;
if(n<0){
cout<<'-';
}
n=abs(n);
while(n){
ans=ans*10+n%10;
n/=10;
}
cout<<ans<<endl;
}
```能帮到的话求关QAQ
by dream_dad @ 2024-08-22 11:27:22
@HuangZihan181 甚至这样
#include<bits/stdc++.h>
using namespace std;
int n,s=0;
int main()
{
cin>>n;
while(n) s=s*10+n%10,n/=10;
cout<<s;
return 0;
}
by zxz114514 @ 2024-08-22 11:29:53
@HuangZihan181
#define ll long long
#define l int
#define d double
const int N = 201000 ;
using namespace std;
int main ()
{
ll n ;
cin >> n ;
if (n == 0)
{
cout << 0 ;
return 0;
}
if (n < 0) cout << "-" ;
ll a = abs(n) ;
while (a % 10 == 0) a /= 10;
while (a != 0)
{
cout << a % 10 ;
a /= 10;
}
}```
by ccch1ennn @ 2024-08-22 11:31:18
你的代码
#include<bits/stdc++.h>
using namespace std;
string n,ans;
int a;
int main(){
cin>>n;
if(n=="0") {
cout<<0;
return 0;
}//加个特判
int l=n.length();//这里改一下
if(n[0]=='-'){
a=1;
cout<<'-';
}
for(int i=l-1,j=0;i>=a;i--,j++){
ans=ans+n[i];
}
if(ans[0]=='0'){
ans.erase(0,ans.find_first_not_of('0'));
}
cout<<ans;
return 0;
}
by HuangZihan181 @ 2024-08-22 11:31:45
我问这个的意思是让你们帮我看看我这代码有什么问题。 @违规用户名K&xs3Z^ @dream_dad @zxz114514
by HuangZihan181 @ 2024-08-22 11:32:37
@ccch1ennn thanks!
by BoooFar @ 2024-08-22 11:49:27
@dream_dad 这个代码好欸,就是负数能过吗
by dream_dad @ 2024-08-22 12:07:34
AC了
by wisper_lou @ 2024-08-23 22:52:57
@HuangZihan181 #1就是输入输出为0的情况。