题解 | #字符个数统计#
字符个数统计
https://www.nowcoder.com/practice/eb94f6a5b2ba49c6ac72d40b5ce95f50
简洁代码
#include <iostream> #include <set> #include <string> using namespace std; int main() { string str; set<char> s; cin >> str; for (int i = 0; i < str.size(); i++) { if (!(str[i] >= 0 && str[i] <= 127)) { // 检验[0,127]边界 continue; } if (str[i] == '\n') { // 检验换行符 break; } s.emplace(str[i]); } cout << s.size(); }