zoukankan      html  css  js  c++  java
  • POJ1007

    哎,这是手贱了,用java写一点都不爽,可能是我不会用java吧T_T。

    这题由于数据范围小,水水就过了。

    import java.util.*;
    
    public class Main {
        public static void main(String[] args) {
    
            Astruct[] s = new Astruct[105];
            
            Scanner in = new Scanner(System.in);
            
            int m = in.nextInt();
            int n = in.nextInt();
            
            for (int i=0; i<n; i++)
            {
                s[i] = new Astruct(in.next());
                for (int j=0; j<m-1; j++)
                    for (int l=j+1; l<m; l++)
                        if (s[i].str.charAt(j) > s[i].str.charAt(l))
                            s[i].count++;
            }
    
            sort(0, n-1, s);
            for (int i=0; i<n; i++)
                System.out.println(s[i].str);
            
        }
        
        public static void sort(int l, int r, Astruct[] s)
        {
            int mid = s[(l+r) / 2].count;
            int i = l, j = r;
            while (i <= j)
            {
                while (s[i].count < mid) i++;
                while (s[j].count > mid) j--;
                if (i <= j)
                {
                    if (s[i].count != s[j].count)
                        s[i].swap(s[j]);
                    i++; j--;
                }
            }
            if (i<r) sort(i,r,s);
            if (l<j) sort(l,j,s);
        }
    }
    
    class Astruct
    {
        public Astruct(String ss)
        {
            str = ss;
            count = 0;
        }
        public Astruct() {}
        
        public void swap(Astruct a)
        {
            int temp = count; count = a.count; a.count = temp;
            String ss = str; str = a.str; a.str = ss;
        }
    
        public String str;
        public int count;
    
    }
  • 相关阅读:
    js MD5加密后的字符串
    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
    归并排序
    C#分解质因数
    C#找出第n到m个素数之间所有之和
    C#打印0到100的素数
    for循环练习
    express总结(一)
    Nodejs总结(一)
    Webpack配置及使用
  • 原文地址:https://www.cnblogs.com/ay27/p/2923811.html
Copyright © 2011-2022 走看看