• poj 2159 java


         这是前几天做的,不算做完,只能算运行成功,因为运行时间挺久的,严重超时,要注意

     1 import java.io.*;
     2 import java.util.ArrayList;
     3 import java.util.Collections;
     4 import java.util.List;
     5 
     6 public class Main{
     7     public static void main(String args[]){
     8         
     9         BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
    10         
    11         String source,cipher;
    12         char[] c1,c2;
    13         boolean flag=true;
    14         
    15         try{
    16         
    17         while((cipher=read.readLine())!=null){
    18             source = read.readLine();
    19             
    20             c1  = cipher.toCharArray();
    21             c2  = source.toCharArray();
    22             
    23             List<Integer> list1 = getList(c1);
    24             List<Integer> list2 = getList(c2);
    25             
    26             
    27             if(list1.size() != list2.size()){
    28                 flag = false;
    29             }else{
    30                 
    31                 for(int i=0;i<list1.size();i++){
    32                     
    33                     Collections.sort(list1);
    34                     Collections.sort(list2);
    35                     
    36                     if(list1.get(i)!=list2.get(i)){
    37                         flag = false;
    38                         break;
    39                     }
    40                 }                
    41             }
    42             
    43             if(flag){
    44                 System.out.println("YES");
    45             }else{
    46                 System.out.println("NO");
    47             }
    48             
    49             
    50         }
    51         }catch(Exception e){
    52             e.printStackTrace();
    53         }
    54         
    55     }
    56     
    57     public static List<Integer> getList(char[] c){
    58         
    59         List<Integer> list = new ArrayList<Integer>();
    60         int index=0;
    61         String used =""; //记录已经出现过的字母
    62         
    63         for(int i=0;i<c.length;i++){
    64             if((index=used.indexOf(c[i]))==-1){
    65                 
    66                 used+=c[i];
    67                 list.add(1);
    68                 
    69             }else{
    70                 list.set(index, (Integer)list.get(index)+1);
    71             }
    72         }
    73         
    74         return list;
    75     }
    76 }
    View Code
  • 相关阅读:
    c# 如何利用异或运算进行简单加密解密
    五分钟读懂UML类图
    深入浅出UML类图
    WPF中DPI的问题
    .NET调用JAVA的WebService方法
    动态调用WebService(C#) (非常实用)
    Docker入门
    idea开发shell脚本并运行
    SpringEl表达式解析
    Navicate 许可证
  • 原文地址:https://www.cnblogs.com/sasaxu/p/3247901.html
Copyright © 2020-2023  润新知