http://noi.openjudge.cn/ch0107/15/
"""
1.7 编程基础之字符串 15 整理药名
http://noi.openjudge.cn/ch0107/15/
Python字母大小写的转换(两种方法)
https://blog.csdn.net/u014642915/article/details/103149769
https://zhidao.baidu.com/question/653942894808807205.html
https://ask.csdn.net/questions/7556562
"""
n=int(input())
List=[]
for i in range(n):
name=input()
List.append(name)
for i in List:
if i[0]>='a'and i[0]<='z':
print(i.capitalize())
else:
if i[0]>='A' and i[0]<='Z':
print(i.capitalize())
else:
print(i.lower())
参考的链接:
https://zhidao.baidu.com/question/653942894808807205.html
https://ask.csdn.net/questions/7556562
C++代码:
/*
1.7编程基础之字符串_15整理药名
http://noi.openjudge.cn/ch0107/15/
1139:整理药名
http://ybt.ssoier.cn:8088/problem_show.php?pid=1139
*/
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main( void )
{
//freopen("a.in","r",stdin);
//freopen("b.out","w",stdout);
char a[100+10];
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a;
//gets(a);
int len=strlen(a);
if(a[0]>='a' && a[0]<='z')
{
a[0]=a[0]+'A'-'a';
}
//cout<<a[0];
for(int j=1;j<len;j++)
{
if(a[j]>='A' && a[j]<='Z')
{
a[j]=a[j]-'A'+'a';
}
//cout<<a[j];
}
for(int j=0;j<len;j++)
{
cout<<a[j];
}
cout<<endl;
//a[100]={0};
a[0]='\0';
}
return 0;
}
/*
1.7编程基础之字符串_15整理药名
http://noi.openjudge.cn/ch0107/15/
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,i,j,len;
//定义数组存放原药名
char x[21];
cin>>n;
//输入药名并进行处理
for(i=0;i<n;i++)
{
cin>>x;
len=strlen(x);
for(j=0;j<len;j++)
{
//若为第一个小写字母,转为大写字母
if(j==0&&x[j]>='a'&&x[j]<='z')
x[j]-=32;
//若为大写字母,转为小写字母
if(j>0&&x[j]>='A'&&x[j]<='Z')
x[j]+=32;
}
//输出药名
cout<<x<<endl;
}
return 0;
}