Hướng dẫn giải của Phân loại từ

Chỉ dùng lời giải này khi không có ý tưởng, và đừng copy-paste code từ lời giải này. Hãy tôn trọng người ra đề và người làm lời giải.


Nộp code mẫu trước khi tự giải được bài tập là một hành vi có thể bị ban.

Tác giả: bachminhkhang

Code tham khảo

#include<bits/stdc++.h>

using namespace std;

string s;
int n;
vector<string> res1, res2, res3;
void input()
{
    cin >> n >> s;
}

bool check(string S)
{
    if(int(S.size()) == 1) return true;
    if(S[0] == '0') return false;
    return true;
}

void solve()
{
    bool ok1 = false, ok2 = false, ok3 = false;
    string tmp = "";
    for(int i = 0; i <= n; ++i)
    {
        if(i == n || s[i] == ',' || s[i] == ';')
        {
            if(ok1 && !ok2 && !ok3)
            {
                res1.push_back(tmp);
            }
            else if(!ok1 && ok2 && !ok3 && check(tmp))
            {
                res2.push_back(tmp);
            }
            else if(int(tmp.size()) != 0) res3.push_back(tmp);
            tmp = "";
            ok1= false;
            ok2 = false;
            ok3 = false;
        }
        else
        {
            if(s[i] >= 'A' && s[i] <= 'Z') ok1 = true;
            if(s[i] >= '0' && s[i] <= '9') ok2 = true;
            if(s[i] == '.') ok3 = true;
            tmp += s[i];
        }
    }
    if(int(res1.size()))
        for(auto &S : res1) cout << S << ' ';
    else cout << '-';
    cout << '\n';
    if(int(res2.size()))
        for(auto &S : res2) cout << S << ' ';
    else cout << '-';
    cout << '\n';
    if(int(res3.size()))
        for(auto &S : res3) cout << S << ' ';
    else cout << '-';
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    input();
    solve();
    return 0;
}

Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.