[Xâu Ký Tự Cơ Bản]. Bài 11. Ngày sinh

View as PDF

Submit solution

Points: 1.00 (partial)
Time limit: 1.0s
Memory limit: 256M
Input: stdin
Output: stdout

Problem source:
28Tech
Problem type
Allowed languages
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

Cho ngày sinh của một người theo dạng ngày/tháng/năm. Bạn hãy chuẩn hóa ngày sinh này về dạng dd/mm/yyyy.

Ví dụ : nếu ngày sinh là 1/10/2002 thì được chuẩn hóa thành 01/10/2002, hoặc 5/2/2002 thì được chuẩn hóa thành 05/02/2002.


Đầu vào

Dòng duy nhất chứa 1 xâu mô tả ngày sinh


Giới hạn

Các phần ngày, tháng, năm được phân cách nhau bởi dấu /, năm là số có 4 chữ số.


Đầu ra

In ra ngày sinh sau khi chuẩn hóa


Ví dụ :

Input 01
30/7/1991
Output 01
30/07/1991

Comments

Please read the guidelines before commenting.



  • -1
    nhandzvc  commented on Jan. 14, 2026, 1:26 p.m.
    #include <bits/stdc++.h>
    #define ll long long
    #define endl "\n"
    #define suy ios_base::sync_with_stdio(0);cin.tie(0)
    using namespace std;
    
    void solve()
    {
        string s; cin >> s;
        int p1 = s.find('/');
        int p2 = s.find('/', p1 + 1);
    
        string d = s.substr(0, p1);
        string m = s.substr(p1 + 1, p2 - p1 - 1);
        string y = s.substr(p2 + 1);
    
        if(d.size() == 1) d = "0" + d;
        if(m.size() == 1) m = "0" + m;
    
        cout << d << "/" << m << "/" << y << endl;
    }
    
    int main()
    {
        suy;
        solve();
        return 0;
    }
    

  • -1
    EliseNaltaya  commented on Jan. 8, 2026, 4:10 a.m.

    Gợi ý: Dùng string rồi tách ra ngày, tháng, năm, nếu thấy ngày/tháng có 1 số thì thêm 0 ở đầu


  • -2
    bennie15025_meow  commented on Jan. 2, 2026, 9:17 a.m.

    Code AC 100 %: https://onecompiler.com/cpp/449ddk2uc


    • 0
      lmnlmnlmn  commented on Jan. 17, 2026, 12:45 p.m.

      cần j phức tạp v bro 2 if là đc mà #include <bits/stdc++.h> using namespace std; int main() { iosbase::syncwith_stdio(false); cin.tie(NULL); string s; cin>>s;
      if(s[2]!='/') s.insert(0,"0"); if(s[5]!='/') s.insert(3,"0"); cout<<s; return 0; }


  • -5
    Kaybe  commented on March 31, 2025, 11:59 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.