Java常用类、集合框架类1
A 时间日期格式转换(SDUT 2246)(SimpleDateFormat用法)
转换的df2里面时间是US,上面的df1可以是CHINA或者US。
package test;
import java.util.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n;
n = sc.nextInt();
sc.nextLine();
SimpleDateFormat df1 = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss",Locale.US);
SimpleDateFormat df2 = new SimpleDateFormat("MM/dd/yyyy-hh:mm:ssa",Locale.US);
String s;
while(n -- > 0) {
s = sc.nextLine();
try {
System.out.println(df2.format(df1.parse(s)).toLowerCase());
}catch(ParseException e) {
e.printStackTrace();
}
}
}
}
B 小学数学 (SDUT 2445) spilt和Integer.parseInt()用法。
import java.io.*;
import java.util.*;
import java.nio.file.*;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int ans = 0,i;
while (sc.hasNext()) {
String s = sc.nextLine();
String[] a = s.split("\\+|\\-|\\=");
if (!a[2].equals("?")) {
int x1 = Integer.parseInt(a[0]);
int x2 = Integer.parseInt(a[1]);
int x3 = Integer.parseInt(a[2]);
for(i = 0; i < s.length(); i ++) if(s.charAt(i) == '+' || s.charAt(i) == '-')break;
if (s.charAt(i) == '+') {
if (x1 + x2 == x3)
ans++;
}
else {
if(x1 - x2 == x3) ans ++;
}
}
}
System.out.println(ans);
}
}
加密术 (SDUT 2787)
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
String s,t;
while(sc.hasNext()) {
s = sc.next();
t = sc.next();
int num = 0;
int i,j = 0;
int f = 0;
for(i = 0; i < s.length(); i ++) {
for(; j < t.length(); j ++) {
if(s.charAt(i) == t.charAt(j)) {
num ++;
break;
}
if(i != s.length() - 1) {
if(j == t.length()) {
f = 1;
break;
}
}
}
if(f == 1) break;
}
if(num == s.length() && f == 0)
System.out.println("Yes");
else
System.out.println("No");
}
}
}
救基友记2(SDUT 2192) replace用法
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
String s;
int t;
t = sc.nextInt();
while(t-- > 0) {
s = sc.next();
String s1 = "cRazY";
String s2 = "CraZy";
String news1 = "CrAZy";
String news2 = "cRAzY";
s = s.replace(s1, news1);
s = s.replace(s2, news2);
System.out.println(s);
}
sc.close();
}
}
Eddy的难题(SDUT 2271)indexOf用法
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
String s,t;
while(sc.hasNext()) {
s = sc.next();
t = sc.next();
s = s + s;
if(s.length() / 2 < t.length()) {
System.out.println("no");
}
else {
if(s.indexOf(t) != -1) {
System.out.println("yes");
}
else System.out.println("no");
}
}
}
}
Java常用类、集合框架类1的更多相关文章
- Java基础之集合框架类及泛型简介
Collection接口 Collection 通用的常见方法 add()添加一个元素,可以指定脚标 addAll()将一个collection放入 clear()清除 remove()删除元素,返回 ...
- Java集合框架类
java集合框架类图 Collection接口(List.Set.Queue.Stack):
- 第八节:详细讲解Java中的异常处理情况与I/O流的介绍以及类集合框架
前言 大家好,给大家带来详细讲解Java中的异常处理情况与I/O流的介绍以及类集合框架的概述,希望你们喜欢 JAVA 异常 try...catch...finally结构的使用方法 class Tes ...
- Java常用的加密解密类(对称加密类)
Java常用的加密解密类 原文转载至:http://blog.csdn.net/wyc_cs/article/details/8793198 原创 2013年04月12日 14:33:35 1704 ...
- Java基础--说集合框架
版权所有,转载注明出处. 1,Java中,集合是什么?为什么会出现? 根据数学的定义,集合是一个元素或多个元素的构成,即集合一个装有元素的容器. Java中已经有数组这一装有元素的容器,为什么还要新建 ...
- 第51节:Java当中的集合框架Map
简书作者:达叔小生 Java当中的集合框架Map 01 Map提供了三个集合视图: 键集 值集 键-值 映射集 public String getWeek(int num){ if(num<0 ...
- Java中的集合框架-Collection(一)
一,Collection接口 在日常的开发工作中,我们经常使用数组,但是数组是有很多的局限性的,比如:数组大小固定后不可修改,只能存储基本类型的值等等. 基于数组的这些局限性,Java框架就产生了用于 ...
- Java中的集合框架-Collections和Arrays
上一篇<Java中的集合框架-Map>把集合框架中的键值对容器Map中常用的知识记录了一下,本节记录一下集合框架的两个工具类Collections和Arrays 一,Collections ...
- Java中的集合框架-Map
前两篇<Java中的集合框架-Commection(一)>和<Java中的集合框架-Commection(二)>把集合框架中的Collection开发常用知识点作了一下记录,从 ...
- Java中的集合框架-Collection(二)
上一篇<Java中的集合框架-Collection(一)>把Java集合框架中的Collection与List及其常用实现类的功能大致记录了一下,本篇接着记录Collection的另一个子 ...
随机推荐
- Linux权限管理:ACL 权限
1.ACL 是什么 ACL的全称是 Access Control List (访问控制列表) ,一个针对文件/目录的访问控制列表.它在UGO权限管理的基础上为文件系统提供一个额外的.更灵活的权限管理机 ...
- hdu 1045 要求全部逐一搜索完的深搜
#include<stdio.h> #include<string.h> int visit[10][10]; char map[10][10]; int n,ans,ss,t ...
- 【转发】Java split()用法
特殊情况有 * ^ : | . \ 一.单个符号作为分隔符 String address="上海\上海市|闵行区\吴中路"; String[] splitAddress=addr ...
- OpenSSL 1.1.1 国密算法支持
OpenSSL 1.1.1 国密算法支持 https://www.openssl.org/ https://github.com/openssl/openssl OpenSSL 1.1.1 新特性: ...
- 免root xshell连接termux
免root实现xshell连接termux termux为安卓手机上的一款模拟linux终端的应用,由于手机上打字比较麻烦,所以想到了用电脑上的xshell通过ssh连接termux,以实现电脑控制t ...
- POJ1611(The Suspects)--简单并查集
题目在这里 关于SARS病毒传染的问题.在同一个组的学生是接触很近的,后面也会有新的同学的加入.其中有一位同学感染SARS,那么该组的所有同学得了SARS.要计算出有多少位学生感染SARS了.编号为0 ...
- vue 后台管理系统菜单权限管理
来自:https://www.cnblogs.com/fqh123/p/11094296.html 侵删 login登录方法 login() { if (!this.username) { retur ...
- javascript/js实现 排序二叉树数据结构 学习随笔
二叉树是一种数据结构.其特点是: 1.由一系列节点组成,具有层级结构.每个节点的特性包含有节点值.关系指针.节点之间存在对应关系. 2.树中存在一个没有父节点的节点,叫做根节点.树的末尾存在一系列没有 ...
- OpenStack kilo版(3) Nova部署
部署在controller和compute节点 配置数据库 MariaDB [(none)]> CREATE DATABASE nova; Query OK, 1 row affected ( ...
- hexo Yelee 主题的busuanzi网站统计没数字显示问题解决
j进入你的Yelee主题路径: themes\yelee\source\css\_partial 修改该路径下的: footer.styl 修改文件内容: 将内容改为: 然后你的站点就可以了