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;
}
}
}
张旋(zxsoft)
如对本文有什么疑问,请在下面写下留言,谢谢!
查看全文
相关阅读:
Java面试题(转)
哪种方式更适合在React中获取数据?
vue学习之深入响应式原理
还不会用FindBugs?你的代码质量很可能令人堪忧
几道大数据面试题(转)
【Medium翻译】Java抽象类有什么用?
深入理解Kafka必知必会(上)
(八十六)c#Winform自定义控件-表格优化(转载)
IDEA 配置及常用快捷键
Markdown 复杂公式&常用符号
原文地址:https://www.cnblogs.com/zxsoft/p/938082.html
最新文章
DHCP中继
小游戏二之---------------五子棋
排序算法03------------快速排序
排序算法02----------------选择排序
排序算法01------------------------------------冒泡排序
小游戏一之---------贪食蛇教程
C语言指针一些常见的错误用法
C语言指针的一些用法
python网课自动刷课程序-------selenium+chromedriver
MySql数据库的一些基本操作---------------SQL语法
热门文章
一些适合初学者的C/C++语言开发环境(IDE)
MFC/QT 学习笔记(三)——MFC模板创建
MFC/QT 学习笔记(二)——MFC入门
MFC/QT 学习笔记(一)——认识windows基础库
<Wonder Woman> 摘抄
U盘装系统/win to go制作笔记
C++ Primer 抄书笔记(一)
创业心得:前言
OV5640摄像头配置一些值得注意的关键点(三)
微信开发API(转)
Copyright © 2011-2022 走看看