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的另一个子 ...
随机推荐
- JQuery 的优先级
1.使用最新的jQuery版本 2.用对选择器. 2.1 jquery最快的选择器是ID选择器:来源于js的getElementById()方法 注释:需要选择多个元素,必然涉及到Dom遍历和循环 ...
- oracle 根据时间字段查询
oracle 根据时间字段查询数据 ROWNUM 是对前面查询的记录做限制,比如查询的记录 > 2000 条,那么只取前面的 2000 条 ''' SELECT * FROM (SELECT C ...
- J.U.C之重入锁:ReentrantLock
此篇博客所有源码均来自JDK 1.8 ReentrantLock,可重入锁,是一种递归无阻塞的同步机制.它可以等同于synchronized的使用,但是ReentrantLock提供了比synchro ...
- 搭建一个简单的React项目
我是使用了create-react-app来搭建的基本框架,其中的原理和vue-cli差不多的脚手架.(当然也可以自己配置项目目录,这里我偷了一下懒) npm install -g create-re ...
- js 单引号和双引号相互替换的实现方法
1.双引号替换成单引号 var domo = JSON.stringify(address).replace(/\"/g,"'"); var a = {a:1,b:2}; ...
- Jlink调试S5PV210
安装CDT C/C++ Development Toolkit,使eclipse可以开发C/C++项目 Help–>Install New Software中输入:http://download ...
- 某公司git代码管理,到如何上线
- PAT_B 20
这道题就是简单的贪心,有几个注意点: 1.又是一个单体有多个属性(即月饼有总量,总价,单价几个属性),这个时候可以考虑使用struct结构,我还是傻傻使用pair,还是没有养成习惯,幸好这道题存下来两 ...
- Ignatius and the Princess IV (简单DP,排序)
方法一: 直接进行排序,输出第(n+1)/2位置上的数即可. (容易超时,关闭同步后勉强卡过) #include<iostream> #include<cstdio> # ...
- JDBC课程2--实现Statement(用于执行SQL语句)--使用自定义的JDBCTools的工具类静态方法,包括insert/update/delete三合一
/**JDBC课程2--实现Statement(用于执行SQL语句) * 1.Statement :用于执行SQL语句的对象: * 1): 通过Connection 的createStatement( ...