問題描述
輸入一個小寫字母,轉換成大寫字母。
輸入格式
輸入小寫字母
輸出格式
輸出轉換後的大寫字母
樣例輸入
a
樣例輸出
A
代碼:
#include <algorithm>
#include <stdio.h>
using namespace std;
int main ()
{
char a;
scanf("%c",&a);
printf("%c",a-32);
return 0;
}
這是比較正常的寫法,就是用ascll碼的內插補點來寫。
除此之外還可以用大小寫轉換的一些函數來寫。
例如:
#include <iostream>
using namespace std;
int main ()
{
char a;
cin>>a;
cout<<(char)toupper(a);
return 0;
}
這樣顯然效率更高,也更加的簡介。
下面附上toupper();函數的一些用法。
C++大小寫轉換函數 之 toupper()和tolower()函數的用法總結