随笔 - 147  文章 - 71  trackbacks - 0
<2009年10月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

常用链接

留言簿(1)

随笔分类(146)

随笔档案(147)

文章分类(28)

文章档案(28)

喜欢的Blog

搜索

  •  

最新评论

阅读排行榜

评论排行榜

http://acm.fjnu.edu.cn/show?problem_id=3008
在>或<情况下可能不存在完美字符串。
import java.util.*;
import java.io.*;

public class ACM_3008{
    
    
public static void sort1(String s,char[] c){
        
int i,j,k,n=c.length;
        
boolean find=true;
        
for(i=0;i<n-1 && find;i++){
            
char t=c[i];
            k
=i;
            
for(j=i+1;j<n;j++){
                
if(c[j]>t){
                    t
=c[j];
                    k
=j;
                }

                
else if(c[j]==t){
                    find
=false;
                    
break;
                }

            }

            
if(k!=i)
            
{
                
char tmp=c[i];
                c[i]
=c[k];
                c[k]
=tmp;
            }

        }

        
if(find){
            
for(i=0;i<n;i++)
                System.out.print(c[i]);
            System.out.println();
        }

        
else
            System.out.println(s);
    }

    
    
public static void sort2(String s,char[] c){
        
int i,j,k,n=c.length;
        
boolean find=true;
        
for(i=0;i<n-1 && find;i++){
            
char t=c[i];
            k
=i;
            
for(j=i+1;j<n;j++){
                
if(c[j]<t){
                    t
=c[j];
                    k
=j;
                }

                
else if(c[j]==t){
                    find
=false;
                    
break;
                }

            }

            
if(k!=i)
            
{
                
char tmp=c[i];
                c[i]
=c[k];
                c[k]
=tmp;
            }

        }

        
if(find){
            
for(i=0;i<n;i++)
                System.out.print(c[i]);
            System.out.println();
        }

        
else
            System.out.println(s);
    }

    
    
public static void sort3(char[] c){
        
int i,j,k,n=c.length;
        
for(i=0;i<n-1;i++){
            
char t=c[i];
            k
=i;
            
for(j=i+1;j<n;j++){
                
if(c[j]>=t){
                    t
=c[j];
                    k
=j;
                }

            }

            
if(k!=i)
            
{
                
char tmp=c[i];
                c[i]
=c[k];
                c[k]
=tmp;
            }

        }

        
for(i=0;i<n;i++)
            System.out.print(c[i]);
        System.out.println();
    }

    
    
public static void sort4(char[] c){
        
int i,j,k,n=c.length;
        
for(i=0;i<n-1;i++){
            
char t=c[i];
            k
=i;
            
for(j=i+1;j<n;j++){
                
if(c[j]<=t){
                    t
=c[j];
                    k
=j;
                }

            }

            
if(k!=i)
            
{
                
char tmp=c[i];
                c[i]
=c[k];
                c[k]
=tmp;
            }

        }

        
for(i=0;i<n;i++)
            System.out.print(c[i]);
        System.out.println();
    }

    
    
public static void main(String rgs[]) throws Exception
    
{
        BufferedReader stdin 
= 
            
new BufferedReader(
                
new InputStreamReader(System.in));        
        String line 
= stdin.readLine();
        String s 
= line;
        
char[] c = s.toCharArray();
        line 
= stdin.readLine();
        String t 
= line;
        
if(t.equals(">"))
            sort1(s,c);
        
else if(t.equals("<"))
            sort2(s,c);
        
else if(t.equals(">="))
            sort3(c);
        
else
            sort4(c);
    }

}
posted on 2009-10-17 10:14 飞翔天使 阅读(230) 评论(0)  编辑  收藏 所属分类: ACM

只有注册用户登录后才能发表评论。


网站导航: