You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.5 KiB
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
int main()
{
char buf[30], *sp;
scanf("%s", buf);
if (sp = strchr(buf, '.'))
{
for (char *p1 = buf, *p2 = sp; p1 < p2;)
iter_swap(p1++, --p2);
for (char *p1 = sp + 1, *p2 = buf + strlen(buf); p1 < p2;)
iter_swap(p1++, --p2);
int a, b;
sscanf(buf, "%d.%d", &a, &b);
while (a && a % 10 == 0) a /= 10;
while (b && b % 10 == 0) b /= 10;
printf("%d.%d", a, b);
}
else if (sp = strchr(buf, '/'))
{
for (char *p1 = buf, *p2 = sp; p1 < p2;)
iter_swap(p1++, --p2);
for (char *p1 = sp + 1, *p2 = buf + strlen(buf); p1 < p2;)
iter_swap(p1++, --p2);
int a, b;
sscanf(buf, "%d/%d", &a, &b);
while (a && a % 10 == 0) a /= 10;
while (b && b % 10 == 0) b /= 10;
printf("%d/%d", a, b);
}
else if (sp = strchr(buf, '%'))
{
for (char *p1 = buf, *p2 = sp; p1 < p2;)
iter_swap(p1++, --p2);
unsigned long long a;
sscanf(buf, "%llu", &a);
while (a && a % 10 == 0) a /= 10;
printf("%llu%%", a);
}
else
{
for (char *p1 = buf, *p2 = buf + strlen(buf); p1 < p2;)
iter_swap(p1++, --p2);
unsigned long long a;
sscanf(buf, "%llu", &a);
while (a && a % 10 == 0) a /= 10;
printf("%llu", a);
}
return 0;
}