Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define task "XEPHANG"
- #include <iostream>
- #include <cstdio>
- using namespace std;
- using ll = long long;
- using ld = long double;
- constexpr int N = 50 + 5;
- struct Number
- {
- string s;
- // Nhập dữ liệu
- friend istream &operator>>(istream &in, Number &x)
- {
- in >> x.s;
- return in;
- }
- // Xuất dữ liệu
- friend ostream &operator<<(ostream &out, Number &x)
- {
- out << x.s;
- return out;
- }
- bool operator<(const Number &a)
- {
- int sign1 = 1, sign2 = 1;
- int piv1 = 0, piv2 = 0;
- string Int1, Real1,
- Int2, Real2;
- if (s[0] == '-')
- {
- sign1 = -1;
- ++piv1;
- }
- if (a.s[0] == '-')
- {
- sign2 = -1;
- ++piv2;
- }
- // Trái dấu
- if (sign1 < sign2)
- return true;
- else if (sign1 > sign2)
- return false;
- while (piv1 < (int)s.size() && s[piv1] != '.')
- Int1.push_back(s[piv1++]);
- while (piv2 < (int)a.s.size() && a.s[piv2] != '.')
- Int2.push_back(a.s[piv2++]);
- // Phần nguyên khác nhau
- if (Int1.size() > Int2.size())
- return (sign1 == -1);
- else if (Int1.size() < Int2.size())
- return (sign1 == 1);
- else if (Int1 > Int2)
- return (sign1 == -1);
- else if (Int1 < Int2)
- return (sign1 == 1);
- ++piv1;
- ++piv2;
- while (piv1 < (int)s.size())
- Real1.push_back(s[piv1++]);
- while (piv2 < (int)a.s.size())
- Real2.push_back(a.s[piv2++]);
- // Phần thực có thể có các số 0 vô nghĩa
- while (!Real1.empty() && Real1.back() == '0')
- Real1.pop_back();
- while (!Real2.empty() && Real2.back() == '0')
- Real2.pop_back();
- // Phần thực khác nhau
- if (Real1.size() > Real2.size())
- return (sign1 == -1);
- else if (Real1.size() < Real2.size())
- return (sign1 == 1);
- else if (Real1 > Real2)
- return (sign1 == -1);
- else if (Real1 < Real2)
- return (sign1 == 1);
- // Hai số bằng nhau
- return false;
- }
- } k, a[N];
- int n;
- void Read()
- {
- cin >> n >> k;
- for (int i = 1; i <= n; ++i)
- cin >> a[i];
- }
- void Solve()
- {
- for (int i = 1; i <= n; ++i)
- if (k < a[i])
- {
- // Đã tìm được một đáp án
- cout << i << "\n";
- for (int j = 1; j < i; ++j)
- cout << a[j] << " ";
- cout << k << " ";
- for (int j = i; j <= n; ++j)
- cout << a[j] << " ";
- return;
- }
- cout << n + 1 << "\n";
- for (int i = 1; i <= n; ++i)
- cout << a[i] << " ";
- cout << k;
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if (fopen(task ".INP", "r"))
- {
- freopen(task ".INP", "r", stdin);
- freopen(task ".OUT", "w", stdout);
- }
- Read();
- Solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement