邏輯:一個一個讀入字串,做字串處理(非字母移除 字母轉小寫),再存入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';
}
}
邏輯:一個一個讀入字串,做字串處理(非字母移除 字母轉小寫),再存入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