- 数字反转
为啥这个只有75分
- 2023-10-17 9:45:34 @
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,a;
cin >> n;
if(n>=0)
{
while(n>=10)
{
a=n%10;
cout << a;
n=n/10;
}
cout << n << endl;
return 0;
}
if(n<0)
{
n=abs(n);
if(n%10==0)
n=n/10;
cout << "-";
while(n>=10)
{
a=n%10;
cout << a;
n=n/10;
}
cout << n << endl;
return 0;
}
return 0;
}
3 comments
-
DEV LV 7 @ 2023-10-17 21:29:08
#include<bits/stdc++.h> using namespace std; int main(){ long n,temp,sum=0; cin>>n; if(n<0){ //若为负数,在其前面加上“-”负号 cout<<"-" ; } temp = abs(n); //求出该数的绝对值。 while(temp){ //将原来数temp的最低位通过对10求模,再加上sum10,可将其变为最高位。 sum = sum10+temp%10; temp/=10;//由于个位在上一步已经使用,除去个位。 } cout<<sum; return 0; }
-
2023-10-17 21:06:08@
#include<bits/stdc++.h> using namespace std; int main() { int N,a[15]={-1},k=0; cin>>N; if(N<0) { N=-N; cout<<"-"; } if(N==0) cout<<0; for(int i=0;N>0;i++) { a[i]=N%10; N=N/10; k++; } int start=0; while(a[start]==0&&start<k) { start++; } for(int i=start;i<k;i++) cout<<a[i]; return 0; }
-
2023-10-17 16:27:28@
你自己测一下啊,你这输个380输出是083
- 1
Information
- ID
- 583
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 4
- Tags
- (None)
- # Submissions
- 179
- Accepted
- 77
- Uploaded By