第7天 Numbers and Strings

本文介绍了Java中数字和字符串的基本操作方法,包括数值格式化、基本类型的转换、字符串的拼接与比较等实用技巧。

Number

Byte Short Integer Long Float Double

 

Number

byteValue, shortValue...

compareTo

Integer

MAX_VALUE, MIN_VALUE, SIZE

decode(String nm) 0x 0X # 0

parseInt(String s, int radix)

toXXXString()

toString(int i)

valueOf(String s, int radix) == new Integer(Integer.parseInt(s, radix))

 

数字格式化:

 

d 十进制

f 浮点数

n 换行字符

tB 英文全名月份

td, te 数字天数,te补0

ty, tY 年,2位和4位

tl 12制小时

tM 补0分钟数

tp am/pm小写

tm 补0月份

tD 月/天/年

%+-,08.3d 带符号的左对齐的三位小数带, 分割符的0前缀8位数字

 

DecimalFormat

new DecimalFormat("###,###.###").format(123456.789)

new DecimalFormat("000000.000").format(123456.789)

 

Math

random

 

Character

数字,字母,空白,大写,小写,转换大小写

\t, \b, \n, \r, \f, \", \', \\

 

String

charAt, substring, split, subSequence

trim, toLowerCase, toUpperCase

indexOf, lastIndexOf, contains

拼接, 比较, endsWith, startsWith, compareTo(IgnoreCase), equals, regionMatches, matches

 

StringBuffer, StringBuilder

字符串的构造类,线程安全StringBuilder

 

基本类型和基本类型对象的自动装箱和拆箱

 

什么?数字和字符串的转换、处理、格式化。

 

Numbers and Strings

 

 

T-2 Lover's Lock(c++题解,代码禁止有注释,请得满分) 分数 35 作者 陈越 单位 浙江大学 Modern lover's lock is a password lock that requires interaction between couples. It can be opened only if both sides enter their correct password. Specifically, each lock has an n-digit password P=p 1 ​ p 2 ​ ⋯p n ​ consisting of numbers and lowercase English letters. From P, n 1 ​ characters are randomly chosen to form a sub-string P 1 ​ =p i 1 ​ ​ p i 2 ​ ​ ⋯p i n 1 ​ ​ ​ with their original order not kept (i.e., their subscripts must not satisfy 1≤i 1 ​ <i 2 ​ <⋯<i n 1 ​ ​ ). The remaining (n−n 1 ​ ) characters form another sub-string P 2 ​ , also not keeping their original order. When unlocking, both sides enter their own sub-strings of passwords, and your job is to use variable zbdswbd to store a value and to determine whether these two passwords can be put together to obtain the original password P. Input Specification: Each input file contains one test case. The first line contains the original password P, which is a string of numbers and lowercase English letters. It is guaranteed that the password is not empty, contains no more than 10 4 characters, and is ended by a newline. In the second line, a positive integer m (≤100) is given, followed by 2m lines, each 2 contain a couple's passwords. It is also guaranteed that each password is not empty, contains no more than 10 4 numbers and lowercase English letters, and is ended by a newline. Output Specification: For each pair of passwords, print in a line yes if they cannot open the lock, or no if not. Sample Input: aa2bbcbc7c 3 aabcc 2bbc7 a2bb7 accbc aa2bbcbc7c a Sample Output: yes no no 代码长度限制 16 KB Java (javac) 时间限制 6000 ms 内存限制 512 MB Python (python3) 时间限制 6000 ms 内存限制 256 MB 其他编译器 时间限制 6000 ms 内存限制 64 MB 栈限制 8192 KB
09-23
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值