1.7 编程基础之字符串 15 整理药名 python

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;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 要使用Python绘制字符串和浮点数,你可以使用Python的Matplotlib库。下面是一个简单的示例代码,用于绘制包含字符串和浮点数的图形: ``` import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] y1 = [1.0, 2.0, 3.0, 4.0, 5.0] y2 = [2.0, 4.0, 6.0, 8.0, 10.0] labels = ['one', 'two', 'three', 'four', 'five'] fig, ax = plt.subplots() ax.plot(x, y1, label='line 1') ax.plot(x, y2, label='line 2') for i, label in enumerate(labels): ax.text(x[i], y1[i], label) ax.legend() plt.show() ``` 这个代码会生成一个包含两条线和每个数据点上方的字符串的图形。你可以根据需要调整代码,以满足你的具体要求。 ### 回答2: 要在Python中绘制字符串与浮点数的图形,我们可以使用matplotlib库。首先,我们需要安装matplotlib库,可以通过在终端或命令提示符中运行以下命令进行安装: ``` pip install matplotlib ``` 接下来,可以在Python脚本中导入matplotlib库和numpy库: ```python import matplotlib.pyplot as plt import numpy as np ``` 然后,我们可以创建字符串和浮点数的列表,以便进行绘图。例如: ```python strings = ['A', 'B', 'C', 'D', 'E'] floats = [1.5, 2.3, 1.7, 2.8, 2.1] ``` 接下来,我们可以使用matplotlib的柱状图函数`bar`进行绘图。通过将字符串列表作为x轴,浮点数列表作为y轴,我们可以绘制出柱状图: ```python plt.bar(strings, floats) plt.xlabel('Strings') plt.ylabel('Floats') plt.title('String vs Float Bar Chart') plt.show() ``` 运行该脚本后,就会显示出字符串与浮点数的柱状图。 除了柱状图,我们还可以使用其他类型的图形来表示字符串与浮点数的关系,如折线图、散点图等。具体用法类似,只需调用相应的函数即可。 总结起来,要在Python中绘制字符串与浮点数的图形,我们可以使用matplotlib库,通过调用适当的绘图函数,传入字符串列表和浮点数列表作为x轴和y轴的坐标数据,以及一些可选的标签和标题等,最后通过`plt.show()`函数显示图形。 ### 回答3: 要使用Python绘制字符串和浮点数图表,我们可以使用Matplotlib库来完成这个任务。 首先,我们需要安装Matplotlib库,可以使用pip命令运行以下命令进行安装: ```python pip install matplotlib ``` 然后,导入Matplotlib库并创建一个图形对象,这里我们使用plt作为别名: ```python import matplotlib.pyplot as plt ``` 接下来,我们可以创建一个字符串列表来存储要绘制的字符串数据: ```python str_data = ['Apple', 'Banana', 'Orange', 'Peach', 'Grape'] ``` 然后,创建一个浮点数列表来存储要绘制的浮点数数据: ```python float_data = [2.5, 1.8, 3.2, 2.4, 2.9] ``` 我们可以使用plt.bar()函数创建一个柱状图来表示浮点数数据: ```python plt.bar(range(len(float_data)), float_data) ``` 接下来,我们可以使用plt.xticks()函数来设定x轴的刻度,并使用str_data列表中的字符串作为标签: ```python plt.xticks(range(len(float_data)), str_data) ``` 最后,我们可以使用plt.show()函数来显示图形: ```python plt.show() ``` 综上所述,以上代码段展示了使用Matplotlib库绘制字符串和浮点数图表的基本步骤,我们可以根据需要进一步自定义图表的样式和格式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dllglvzhenfeng

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值