zoukankan      html  css  js  c++  java
  • (C#)ACM考试题的第二题

    这个有点难啊。暂时这么做了做,不符合第二条要求。BBC的话。会有重复的。
    BBC
    BCB
    BCB
    CBB
    虽然筛选不重复的肯定可以实现,不过这肯定不是题目原意。有时间需要重新做一下

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;

    namespace ACM2
    {
        
    class Program
        
    {
            
    static void Main(string[] args)
            
    {
                FileStream fs 
    = new FileStream(args[0], FileMode.Open, FileAccess.Read);
                StreamReader sr 
    = new StreamReader(fs);
                
    string s=sr.ReadLine();
                
    int n = int.Parse(s);
                
    for (int i = 0; i < n; i++)
                
    {
                    s 
    = sr.ReadLine();
                    Console.WriteLine(
    "Case " + (i + 1));
                    Deal(s);
                    
                }

            }

            
    static string Sort(string str)
            
    {
                
    char[] cs = str.ToCharArray(); char temp;
                
    for(int i=0;i<cs.Length;i++)
                    
    for(int j=i;j<cs.Length;j++)
                        
    if (cs[i] > cs[j])
                        
    {
                            temp 
    = cs[i];
                            cs[i] 
    = cs[j];
                            cs[j] 
    = temp;
                        }

                
    return new string(cs);
            }

            
    static void Deal(string str)
            
    {
                
    string mstr = Sort(str);
                
    string[] strs = DealF(mstr);
                
    for (int i = 0; i < strs.Length; i++)
                    Console.WriteLine(strs[i]);
            }

            
    static string[] DealF(string str)
            
    {
                
    if (str.Length == 1)
                    
    return new string[] { str };
                
    if (str.Length == 2)
                
    {
                    
    string[] toRets = new string[2];
                    toRets[
    0= str;
                    toRets[
    1= str.Substring(1)+str.Substring(0,1);
                    
    return toRets;
                }

                
    string c=str.Substring(0,1);
                
    string[] Ret = DealF(str.Substring(1));
                
    string[] toRet = new string[Ret.Length *2];
                
    for (int i = 0; i < toRet.Length; i++)
                
    {
                    
    if (i < toRet.Length / 2)
                        toRet[i] 
    = c + Ret[i];
                    
    else
                        toRet[i] 
    = Ret[i - Ret.Length] + c;
                }

                
    return toRet;
            }

        }

    }

  • 相关阅读:
    Python学习之路【第三篇】--集合
    Python学习之路【第二篇】-pyc简介、Python常用的数据类型及其用法和常用运算符
    Python学习之路【第一篇】-Python简介和基础入门
    NotePad++ 配置Python工作环境
    码农跳槽指南:如何在新公司建立自己的“支配地位”?
    python实现简单的聊天小程序
    真正努力的人,从来不焦虑
    我在公司待了6年,清退我却只花了6分钟
    只有潮水退去后,才知道谁在裸泳
    什么是rpc
  • 原文地址:https://www.cnblogs.com/zxsoft/p/938082.html
Copyright © 2011-2022 走看看