仅供参考,未经过洛谷测试,如若洛谷需微修。
题目链接:P8761 [蓝桥杯 2021 国 BC] 大写 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
方法一:直接上函数(头文件ctype.h)
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main()
{
char w[50];
scanf("%s",w);
int length = strlen(w);
for(int i=0;i<length;i++)
printf("%c",toupper(w[i])); //直接用toupper函数把小写转换成大写
}
方法二:相差32
#include<stido.h>
#include<string.h>
int conversion(int x) //自己定义大小写字母转换函数
{
if(x>=97&&x<=122) //97-122为ASII码表上小写字母十进制范围
return x-32; //ASII码表大写字母与小写字母相差32。
else
return x;
}
int main()
{
char w[50];
scanf("%s",w);
int length = strlen(w);
for(int i=0;i<length;i++)
printf("%c",conversion(w[i]));
}