Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.
Example 1:
Input: "Hello"
Output: "hello"
Example 2:
Input: "here"
Output: "here"
Example 3:
Input: "LOVELY"
Output: "lovely"
题目的要求就是将大写的转化成小写的。
需要注意的知识点:
1. 大写字母的ASCII值是在65-90之间的,小写的是97-122之间的
2. 相同字母的大小写相差32
3. 数字之间的差距最后要转换成字母。
string toLowerCase(string str) {
int length = str.length();
for(int i = 0;i < length ;i++)
{
if(str[i]<= 90 && str[i]>=65)
{
str[i] = char(str[i] + 32);
}
}
return str;
}