当前位置:网站首页>OJ每日一练——整理命名
OJ每日一练——整理命名
2022-06-22 21:00:00 【KJ.JK】
问题描述:
公司对仓库里的货物的命名有明确的要求:
只能包含大小写字母、数字和横杠’-',
如果以字母开头,则首字母必须大写
除首字母外,其它字母必须小写。
Allen之前对货物的命名虽然满足第1条,但第2条和第3条并不规范,请你写个程序帮帮他吧。
输入
第1行一个正整数N,代表有N个货物名字。
之后N行里每行一个货物名字,长度都不超过15个字符。
输出
对于每个货物,输出其规范化后的命名。
样例
输入
4
ChInese
china
2-APPLES
Huawei-Mate-40
输出
Chinese
China
2-apples
Huawei-mate-40
Java代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int n=in.nextInt();
String a[]=new String[n];
for(int i=0;i<n;i++) {
a[i]=in.next();
}
for(int i=0;i<n;i++) {
char b[]=a[i].toCharArray();
for(int j=0;j<b.length;j++) {
if(j==0) {
if(b[j]>='a'&&b[j]<='z') {
for(int m=0;m<26;m++) {
if(b[j]==(char)('a'+m)) {
b[j]=(char)('A'+m);
System.out.print(b[j]);
}
}
}
else {
System.out.print(b[j]);
}
}
else {
if(b[j]>='A'&&b[j]<='Z') {
for(int m=0;m<26;m++) {
if(b[j]==(char)('A'+m)) {
b[j]=(char)('a'+m);
System.out.print(b[j]);
}
}
}
else {
System.out.print(b[j]);
}
}
}
System.out.println();
}
}
}
作者:KJ.JK
文章对你有所帮助的话,欢迎给个赞或者 star,你的支持是对作者最大的鼓励,不足之处可以在评论区多多指正,交流学习
边栏推荐
- [kubernetes series] overview of kubernetes
- Spark SQL 访问json和jdbc数据源
- 保证数据库和缓存的一致性
- 2021-03-06
- A spark app demo
- OJ每日一练——过滤多余的空格
- ArcGIS应用(二十)Arcgis 栅格图像符号系统提示“This dataset does not have valid histogram required for classificati…”
- 为 localStorage 添加过期时间
- 【STM32技巧】使用STM32 HAL库的硬件I2C驱动RX8025T实时时钟芯片
- Redis big key problem
猜你喜欢

2021-04-05

PHP7.3报错undefined function simplexml_load_string()

Install the typescript environment and enable vscode to automatically monitor the compiled TS file as a JS file

'dare not doubt the code, but have to doubt the code 'a network request timeout analysis

Spark RDD Programming Guide(2.4.3)

企业数字化不是各自发展,而是全面SaaS化推进

保证数据库和缓存的一致性

程序员接私活兼职选择

swagger2 使用方法

口令安全是什么意思?等保2.0政策中口令安全标准条款有哪些?
随机推荐
Which securities company is the safest and best choice for stock trading account opening
From 11 hours to 25 seconds -- is there room for optimization?
os.Args[1:]中命令行参数为空时,不执行内部语句
Use the find command
2021-08-26
LeetCode_ Backtracking_ Dynamic programming_ Medium_ 131. split palindrome string
Learn redis with you (11) -- redis distributed lock
好东西要分享啦
DML:Data Manipulation Language 数据操纵语言
Greedy distribution problem (2)
node-fetch下载文件
口令安全是什么意思?等保2.0政策中口令安全标准条款有哪些?
2021-04-16
eslint 简单配置
2021-08-21
Install the typescript environment and enable vscode to automatically monitor the compiled TS file as a JS file
斐波那契数列合集
2021-04-14
Business stability construction ideas based on Cloud Architecture
Zynq ultrascale + rfsoc zcu111 RF clock tree learning 1