#53759: WA(line:112) 求解


kenny980721.tu@gmail.com (有事直接私)

學校 : 國立中興大學附屬高級中學
編號 : 290039
來源 : [220.134.29.87]
最後登入時間 :
2025-09-13 17:26:11

邏輯:一個一個讀入字串,做字串處理(非字母移除 字母轉小寫),再存入set

#include<iostream>
#include<set>
#include<algorithm>

using namespace std;

set<string> words;

int main(){
    string s;
    while(cin >> s){
        s.erase(remove_if(s.begin(), s.end(), [](char c){
            return !isalpha(c);
        }), s.end());
        transform(s.begin(), s.end(), s.begin(), [](char c){
            return tolower(c);
        });
        if(!s.empty()) words.insert(s);
    }
    for(const string &s : words){
        cout << s << '\n';
    }
}


#53766: Re: WA(line:112) 求解


kenny980721.tu@gmail.com (有事直接私)

學校 : 國立中興大學附屬高級中學
編號 : 290039
來源 : [220.134.29.87]
最後登入時間 :
2025-09-13 17:26:11

邏輯:一個一個讀入字串,做字串處理(非字母移除 字母轉小寫),再存入set

#include
#include
#include

using namespace std;

set words;

int main(){
    string s;
    while(cin >> s){
        s.erase(remove_if(s.begin(), s.end(), [](char c){
            return !isalpha(c);
        }), s.end());
        transform(s.begin(), s.end(), s.begin(), [](char c){
            return tolower(c);
        });
        if(!s.empty()) words.insert(s);
    }
    for(const string &s : words){
        cout << s << '\n';
    }
}


已解決

ex:
apple3banana1pineapple
要轉成
apple
banana
pineapple
而不是
applebananapineapple