Open Lu-fm opened 4 years ago
//数字反转,包括分数,小数,百分数;
#include<stdio.h>
#include<string.h>
int k = 0;
int judge(char s[]);
void turnover(char s[], int n);
int main()
{
char s[25],t[25]="0";
int a,i=0,j=0,b;
scanf("%s", s);
while(s[k]!='\0')
k++;
a=judge(s);
turnover(s, a);
turnover(s + a + 1, k-a-1);
while (s[i] == '0' )
i++;
if(s[a]=='.'||s[a]=='%')
{
while(s[k-1]=='0')
k--;
if(i==a) printf("0");
for (j = i; j < k;j++)
t[j-i] = s[j];
printf("%s", t);
if(k==a+1&&s[a]=='.') printf("0");
}
else if(s[a]=='/')
{
if(i==a) printf("0");
b = a+1;
while( s[b]=='0')
b++;
for (j = i; j <= a;j++)
t[j - i] = s[j];
for (j = a-i+1; j < k;j++)
t[j] = s[b + j - a +i-1];
printf("%s", t);
}
else
{
for (j = i; j <k;j++)
t[j - i] = s[j];
printf("%s", t);
}
return 0;
}
int judge(char s[]){
int flag=k, i = 0;
while(*(s+i)!='\0')
{
if(*(s+i)=='/'||*(s+i)=='.'||*(s+i)=='%')
{
flag = i;
break;
}
i++;
}
return flag;
}
void turnover(char s[],int n)
{
char temp[25];
int j;
strcpy(temp, s);
for (j = 0; j < n;j++)
{
*(s+n-j-1) = temp[j];
}
}
(一直没发现是在最开始那里出问题, 感谢><
[有3个点一直过不了,求debug] https://www.luogu.com.cn/problem/P1553