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)
如对本文有什么疑问,请在下面写下留言,谢谢!
查看全文
相关阅读:
kafka的概念
java的多线程:java安全问题产生的原因与JMM的关系
java的多线程:线程安全问题
web自动化之键盘操作
获取cookie里面的sessionid
Python连接mysql数据库
Python 发送Email
Python日志模块
openxl模块从excel里面读取数据
Python读取配置文件
原文地址:https://www.cnblogs.com/zxsoft/p/938082.html
最新文章
[JLOI2011]飞行路线
[note]BSGS & exBSGS
[SCOI2016]萌萌哒
[SHOI2007]园丁的烦恼
BZOJ 1396 识别子串
BZOJ 4556 [HEOI2016/TJOI2016]字符串
后缀数组
hdu 5421 Victor and String
回文树
魔法咒语
热门文章
阿狸的打字机
AC 自动机
斯坦纳树
Phoenix-4.14-cdh5.14.2与hbase-1.2.0-cdh5.14.2集成测试
hbase:ERROR: org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet
kafka 0.8+spark offset 提交至mysql
kafka-spark偏移量提交至redis kafka1.0版本
java.io.NotSerializableException: org.apache.kafka.clients.consumer.ConsumerRecord
如何评估数据质量?
java:并发编程-Callable与Future模式
Copyright © 2011-2022 走看看