NamingConvention
题意:
给一个字符串,删掉所有的'_',然后将‘_'后的第一个字符改成大写。
代码:
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 5 class NamingConvention{ 6 public: 7 string toCamelCase(string str) { 8 string res; res.clear(); 9 for (int i=0; i<str.size(); ++i) { 10 if (str[i] == '_') continue; 11 else if (i >= 1 && str[i - 1] == '_') res.push_back(str[i] + 'A' - 'a'); 12 else res.push_back(str[i]); 13 } 14 return res; 15 } 16 };