关于string类型的大小写转换函数
对于string类型的有力工具
transform(s.begin(), s.end(), s.begin(),::tolower)
大写转小写
transform(s.begin(), s.end(), s.begin(),::toupper)
小写转大写
样例 洛谷P2264
#include<bits/stdc++.h>
using namespace std;
const int N = 1000;
int n; string str[N];
map<string, bool> mp;
int main(){
cin >> n;
for(int i = 1; i <= n; i ++){
string s; cin >> s;
transform(s.begin(), s.end(), s.begin(),::tolower);
mp[s] = 1;
}
char c;
int ans = 0, cnt = 0;
string s = "";
while(~scanf("%c", &c)){
if(c >= 'a' && c <= 'z') s += c;
else if(c >= 'A' && c <= 'Z') s += c;
else{
transform(s.begin(), s.end(), s.begin(),::tolower);
cout << s << endl;
if(mp[s] == 1) ans ++, cnt ++, str[cnt] = s;
mp[s] = 0;
s = "";
}
if(c == '.'){
for(int i = 1; i <= cnt; i ++){
mp[str[i]] = 1; str[i] = "";
}
cnt = 0;
}
}
cout << ans << endl;
return 0;
}