This repository was archived by the owner on May 2, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP1553.cpp
More file actions
60 lines (59 loc) · 2.09 KB
/
P1553.cpp
File metadata and controls
60 lines (59 loc) · 2.09 KB
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
60
//
// Created by RenAhsAcme on 2026/4/18.
//
#include <iostream>
using namespace std;
int main() {
string s;
cin >> s;
bool printed = false;
if (s.find(".") != string::npos) {
auto ptr = s.find(".");
int has_left_zero = 0;
for (int i = static_cast<int>(ptr) - 1; i >= 0; i--) {
if (s[i] != '0') has_left_zero = 1, cout << s[i], printed = true;
if (s[i] == '0' && has_left_zero) cout << s[i], printed = true;
}
if (!printed) cout << "0";
cout << ".";
while (s[ptr + 1] == '0') s.erase(ptr + 1, 1);
for (int i = static_cast<int>(s.length()) - 1; i > ptr; i--) cout << s[i];
if (ptr == s.length() - 1) cout << "0";
return 0;
}
if (s.find("/") != string::npos) {
auto ptr = s.find("/");
int has_left_zero = 0;
for (int i = static_cast<int>(ptr) - 1; i >= 0; i--) {
if (s[i] != '0') has_left_zero = 1, cout << s[i], printed = true;
if (s[i] == '0' && has_left_zero) cout << s[i], printed = true;
}
if (!printed) cout << "0";
cout << "/";
int has_right_zero = 0;
for (int i = static_cast<int>(s.length()) - 1; i > ptr; i--) {
if (s[i] != '0') has_right_zero = 1, cout << s[i];
if (s[i] == '0' && has_right_zero) cout << s[i];
}
if (!has_right_zero) cout << '0';
return 0;
}
if (s.find("%") != string::npos) {
auto ptr = s.find("%");
int has_left_zero = 0;
for (int i = static_cast<int>(ptr) - 1; i >= 0; i--) {
if (s[i] != '0') has_left_zero = 1, cout << s[i], printed = true;
if (s[i] == '0' && has_left_zero) cout << s[i], printed = true;
}
if (!printed) cout << "0";
cout << "%";
return 0;
}
int has_left_zero = 0;
for (int i = static_cast<int>(s.length()) - 1; i >= 0; i--) {
if (s[i] != '0') has_left_zero = 1, cout << s[i], printed = true;
if (s[i] == '0' && has_left_zero) cout << s[i], printed = true;
}
if (!printed) cout << "0";
return 0;
}