74 条题解
-
02868647513 LV 8 @ 2015-09-06 21:00:32
注意开头是0的特殊判断,然后如果0包含在中间别忘记输出!
#include<iostream>
#include<cstdio>
#include<cstring>
#include<math.h>
using namespace std;
int main()
{
bool b=0;
int lena,i=0,j;
char a[1000];
scanf("%s",a);
lena=strlen(a);
if(a[0]=='0'){
printf("0");
return 0;
}
if(a[0]=='-'){
printf("-");
i++;
}
for(j=lena-1;j>=i;j--){
if(a[j]=='0'&&!b){
continue;
}
else{
b=1;
printf("%c",a[j]);
}}
return 0;
} -
02015-09-04 18:27:00@
挺简单的,好无聊啊,加我QQ吧 1342181798
有人玩dota么,QQ约我!!!!!
#include<stdio.h>
#include<stdlib.h>
int main()
{
int b;
int n;
int a[15];
scanf("%d",&n);
if(n<0)
{
printf("-");
n=-n;
}
int i=1;
while(n!=0)
{
// if(n%10!=0)
a[i++]=n%10;
n=n/10;
}
int j;
for(j=1;j<i;j++)
if(a[j]!=0)
{
printf("%d",a[j++]);
break;
}
for(;j<i;j++)
printf("%d",a[j]);
//system("pause");
return 0;
} -
02015-08-18 18:10:11@
#include<vector>
#include<cstdio>
using namespace std;vector<int>v;
int main()
{
int n, bri;
scanf("%d", &n);
if(n < 0){
printf("-");
n = -n;
}
while(n > 0){
v.push_back(n%10);
n /= 10;
}
for(int i=0; i<v.size(); i++)
if(v[i] != 0){
bri = i;
break;
}
for(int i=bri; i<v.size(); i++)
printf("%d", v[i]);
return 0;
}
水一发~~~~ -
02015-08-15 10:46:39@
已AC
C语言 就当一道数学题做
超!级!短!的!代!码!
#include <stdio.h>#include <stdlib.h>
int main()
{
int long long a;
int long long b=0;
scanf("%lld",&a);
while(a)//**a=0时跳出循环 a!=0时继续循环**
{
b=b*10;
b=b+a%10;
a=a/10;
}
printf("%lld",b);
return 0;
} -
02015-05-22 14:26:40@
#include<cstdio>
using namespace std;
char s[15],n;
void Init(){
char ch;
n=0;
while(scanf("%c",&ch),ch!='\n')
s[++n]=ch;
}
void Work(){
int b=1,e=n;
if (s[b]=='-'){
printf("-");
b++;
}
for(int i=n;i>=b;i--)
if (s[i]!='0'){
e=i;
break;
}
for(int i=e;i>=b;i--)
printf("%c",s[i]);
}
int main(){
Init();
Work();
return 0;
} -
02014-12-29 18:03:48@
算是正常的思路了==
编译成功
测试数据 #0: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 556 KiB, score = 10
Accepted, time = 0 ms, mem = 560 KiB, score = 100
代码#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
char str[21];
int flag=0;
scanf("%s",str);
if(str[0]=='-')
{
cout<<'-';
for(int i=strlen(str)-1;i>0;i--)
{
if(str[i]!='0')
{
flag=i;
break;
}
}
for(int i=flag;i>0;i--)
{
cout<<str[i];
}
}
else
{
for(int i=strlen(str)-1;i>=0;i--)
{
if(str[i]!='0')
{
flag=i;
break;
}
}
for(int i=flag;i>=0;i--)
{
cout<<str[i];
}
}
cout<<endl;
return 0;
} -
02014-12-22 20:52:11@
这需要题解?
program ex;
var ans,i,n,x:longint;
num:ansistring;
begin
read(num); x:=1;
if num='0' then
begin
write('0');
exit;
end;if num[1]='-' then
begin
x:=2;
write('-');
end;for i:=length(num) downto 1 do
begin
if num[i]<>'0' then
begin
n:=i;
break;
end;
end;for i:=n downto x do
write(num[i]);end.
-
02014-12-17 22:43:41@
#include <iostream>
#include <cstdio>
#include <cstring>using namespace std;
int main()
{
int n,len;
char st[20];
scanf("%d",&n);
sprintf(st,"%d",n);
len=strlen(st);
if (st[0]=='-') printf("-");
for (len-=1;st[len]=='0';len--);
for (;len>0;len--)
{
printf("%c",st[len]);
}
if (st[0]=='-') printf("\n");
else printf("%c\n",st[0]);
return 0;
} -
02014-10-03 23:03:32@
只能删去开头的0!
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
long n;
cin>>n;
if ( n<0 ){
cout<<"-";
n = -n;
while ( n%10 == 0) n /= 10;
while ( n ){
cout<<n%10;
n/=10;
}
}
else if ( n == 0 ){
cout<<0<<endl;
}
else{
while ( n%10 == 0) n /= 10;
while ( n ){
cout<<n%10;
n/=10;
}
}
return 0;
} -
02014-10-03 16:47:43@
#include <cstdio>
long long int n;
long long int ans(0);int main()
{
using namespace std;scanf("%lld", &n);
while (n)
{
(ans *= 10) += n % 10;
n /= 10;
}printf("%lld", ans);
return 0;
} -
02014-08-25 21:11:32@
Pascal:全AC:
var
i:longint;
n:boolean;
s:string;
begin
readln(i);
if i>=0 then
n:=true
else
n:=false;
i:=abs(i);
if i<>0 then
while i mod 10=0 do i:=i div 10;
str(i,s);
if not(n) then write('-');
for i:=length(s) downto 1 do write(s[i]);
end. -
02014-08-03 11:55:00@
1次
记录信息
评测状态 Accepted
题目 P1756 数字反转
递交时间 2014-08-03 11:54:30
代码语言 C++
评测机 VijosEx
消耗时间 30 ms
消耗内存 272 KiB
评测时间 2014-08-03 11:54:35
评测结果
编译成功测试数据 #0: Accepted, time = 15 ms, mem = 272 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 272 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 268 KiB, score = 10
测试数据 #3: Accepted, time = 15 ms, mem = 272 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 272 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 272 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 272 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 268 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 268 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 272 KiB, score = 10
Accepted, time = 30 ms, mem = 272 KiB, score = 100 -
02014-07-07 19:23:36@
#include <stdio.h>
#include <math.h>
int main(){
int arr[10];
int i,num,original,temp,count=0;scanf("%d",&num);
original=num;
num=abs(num);
for(i=0;i<10;i++) arr[i]=0;
while(num>0){
temp=num;
num=num/10;
arr[count]=temp-num*10;
count++;
}
//output
temp=1;
if(original==0) printf("%d",0);
else if(original<0) printf("-");
for(i=0;i<count;i++){
if(arr[i]==0 && temp) continue;
else{
temp=0;
printf("%d",arr[i]);
}
}
printf("\n");
return 0;
} -
02014-06-01 18:14:06@
program xf;
var
s:string;
a,i,j,n:longint;
begin
readln(s);
n:=1;
if s[1]='-' then begin
write('-');
n:=2
end;
a:=length(s);
while s[a]='0' do a:=a-1;
for j:=a downto n do write(s[j]);
end. -
02014-05-31 15:28:38@
var s,str:string;
len,i,j,t:longint;
begin
readln(str);
len:=length(str);
t:=1;
if str='0' then begin writeln('0'); exit; end;
if str[1]='-' then begin write('-'); t:=2; end;
s:='';
for i:=t to len do
s[len+1-i]:=str[i];
i:=1;
while s[i]='0' do
i:=i+1;
for j:=i to len do
write(s[j]);
writeln;
end. -
02014-05-27 21:43:04@
var n:longint;
begin
readln(n);
if n<0 then write('-');
n:=abs(n);
if n=0 then write(0) else begin
while (n mod 10=0) do n:=n div 10;
while n>0 do begin
writeln(n mod 10);
n:=n div 10;
end;
end;
end.
帮忙看一下哪错了? -
02014-03-07 21:10:32@
#include <iostream>
using namespace std;
char a[20];
int main(int argc,char *argv[])
{
int i;
bool k=0;
cin>>a;
if(a[0]=='-')
{
k=1;
cout<<"-";
}
strrev(a+k);
for(i=k;i<strlen(a+k);i++)
{
if(a[i]!='0')
break;
}
cout<<a+i<<endl;
system("pause");
return 0;
}
100分 -
02014-02-12 20:33:00@
STL的方法,直接利用stringstream读写就完了...:
#include <sstream>
#include <string>
#include <iostream>using namespace std;
int main()
{
long long n;
cin >> n;
int sign = 1;
if( n < 0) sign = -1, n = -n;
stringstream s, v;
s << n;
string num = s.str();int e = num.size() - 1;
for(; e >= 0; --e) v << num[e];v >> n;
cout << n * sign << endl;}
-
02013-11-26 20:33:18@
program Project1;
var s:ansistring;
m1:boolean;
l,i:longint;
begin
readln(s);
m1:=false;
if s[1]='-' then begin
write('-');delete(s,1,1);end;
l:=length(s);
for i:=l downto 1 do begin
if s[i]<>'0' then m1:=true;
if m1 then write(s[i]);
end;
writeln;
readln;
end. -
02013-10-05 20:45:34@
简单,太水了!
var n,nn:string;
i:longint;
begin
readln(n);
if n[1]='-'then begin delete(n,1,1);write('-');end;
nn:='';
for i:=1 to length(n) do nn:=n[i]+nn;
while (nn[1]='0')and(length(nn)<>1)do delete(nn,1,1);
writeln(nn);
end.
先考虑负号,再把数倒过来,然后删‘0’,最后写。