1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| #include <iostream> #include <cstring> const int N = 109; int st; char s[N]; void swap(char &a, char &b) { char t = a; a = b; b = t; } void reverse(char *s, int st, int ed) { int i = st, j = ed; while (i < j) { swap(s[i], s[j]); i++, j--; } } int find_st(char *s, int st, int ed) { for (int i = st; i <= ed; i++) if (s[i] != '0') return i; return 0; } void erase_ed(char *s) { int i = strlen(s) - 1; while (s[i--] == '0'); s[i+2] = '\0'; } void erase_md(char *s, int st) { int i = st; while (s[i] == '0') s[i++] = ' '; } int main() { scanf("%s", s); int len = strlen(s); if (strchr(s, '%') - s >= 0) { reverse(s, 0, len-2); st = find_st(s, 0, len-2); } else if (strchr(s, '.') - s >= 0) { int add = strchr(s, '.') - s; reverse(s, 0, add-1); st = find_st(s, 0, add-1); reverse(s, add+1, len-1); erase_ed(s); if (s[strlen(s)-1] == '.') s[strlen(s)] = '0'; } else if (strchr(s, '/') - s >= 0) { int add = strchr(s, '/') - s; reverse(s, 0, add-1); st = find_st(s, 0, add-1); reverse(s, add+1, len-1); erase_md(s, add+1); for (int i = st; s[i]; i++) if (s[i] != ' ') putchar(s[i]); return 0; } else { reverse(s, 0, len-1); st = find_st(s, 0, len-1); } printf("%s", s + st); return 0; }
|