zoukankan      html  css  js  c++  java
  • 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");
        	  }
          }
        }
    }
    
  • 相关阅读:
    模拟google分页效果
    真理胜于一切 JAVA模拟表单提交
    springboot @vaule注解失效解决办法
    安装cnpm
    公众号微信支付开发
    vue去掉链接中的#
    springboot集成mongoDB简易使用
    Spring boot中使用aop详解
    Promise 的基础用法
    MySQL的if,case语句使用总结
  • 原文地址:https://www.cnblogs.com/lcchy/p/10139443.html
Copyright © 2011-2022 走看看