#include <iostream>
#include <string>
#include <bitset>
#include <cctype>
using namespace std;
int main()
{
bitset<26> alpha_mask;
string strbuf;
char tmpch;
while (cin >> strbuf) {
for (string::size_type index = 0; index != strbuf.size(); ) {
if (isalpha(strbuf[index])) {
tmpch = tolower(strbuf[index]);
if (alpha_mask.test(tmpch - 'a')) {
strbuf.erase(index, 1);
} else {
alpha_mask.set(tmpch - 'a');
++index;
}
} else {
++index;
}
cout << "Debug --> " << alpha_mask << endl;
cout << "Debug --> " << strbuf << endl;
}
cout << "Result >>> " << strbuf << endl;
strbuf.erase(); // strbuf.clear();
alpha_mask.reset();
}
return 0;
}
查了一下C++ Reference,其实string类还有个clear方法来着,可是VC++6.0表示压力很大。
bitset小练习
最新推荐文章于 2023-07-30 16:11:04 发布