本帖最后由 EricHo 于 2012-3-29 16:24 编辑
这道题来源于真实项目代码,实现起来非常简短但考点丰富。别看它不是很难,这么多年可以称得上是灭人无数!
P.S:不考虑正则表达式[查看全文]//请实现下面的函数,输入参数baseStr是一个(可以更改的)字符串,请将其中所有连续出现的多个空格都替换成一个空格,单一空格需保留。//请直接使用baseStr的空间,如需开辟新的存储空间,不能超过o(N)(注意是小o,N是字符串的长度)。返回值是替换后的字符串的长度。
//样例代码为C#,但可以使用任何语言。如需使用任何库函数,必须同时给出库函数的实现。
class Program
{
public static int RemoveMultipleSpaces(char[] baseStr)
{
// TODO
}
}
//样例测试程序(请自行补充更多的测试案例)
[TestFixture]
public class ScannersTest
{
[Test]
public void RemoveOneInnterSpaceBlockTest()
{
char[] input = "abc def".ToCharArray();
int resultLength = Program.RemoveMultipleSpaces(input);
Assert.AreEqual(7, resultLength);
Assert.AreEqual("abc def", new string(input, 0, resultLength));
}
[Test]
public void RemoveTwoInnterSpaceBlocksTest()
{
char[] input = "abc def ghi".ToCharArray();
int resultLength = Program.RemoveMultipleSpaces(input);
Assert.AreEqual(11, resultLength);
Assert.AreEqual("abc def ghi", new string(input, 0, resultLength));
}
[Test]
public void KeepSingleSpaceTest()
{
char[] input = " a b d e ".ToCharArray();
int resultLength = Program.RemoveMultipleSpaces(input);
Assert.AreEqual(9, resultLength);
Assert.AreEqual(" a b d e ", new string(input, 0, resultLength));
}
[Test]
public void AllSpacesTest()
{
char[] input = " ".ToCharArray();
int resultLength = Program.RemoveMultipleSpaces(input);
Assert.AreEqual(1, resultLength);
Assert.AreEqual(" ", new string(input, 0, resultLength));
}
}
如题,可以用汉语、C、php、python、java、vb或“算法语言”中的任意一种表示。
先给一个示例:
[查看全文]粉丝数/关注数 < 0.4 (判定为僵尸粉) 括号内的可以不写
如果要用程序语言,请注明各变量含义
int **a,i;
int m,n;
a=(int**)malloc(m*sizeof(int));
for(i=0;i<m;i++)
a=(int*)malloc(n*sizeof(int));
就是老师要我们设计个程序中,涉及到很多未知大小的数组,是不是可以把上面的代码放到自定的函数中去,通过调用来实现动态空间的开辟。
主要是数组太多,我不想一个一个的开辟,想就通过m,n赋值后直接实现。
请大神指教啊!!
如果不可以放在函数里【貌似是不可以,直接放进去,我试运行了下,出错了额
那有什么办法实现我说的,通过赋值m,n,然后调用函数来开辟的。
额 说的有点乱 请谅解
[查看全文]
Input
首先输入一个拼音列表,每行以“拼音 汉字”的形式输入,比如“wo 我”表示“我”字的拼音是“wo”,会出现拼音相同的情况,比如“wo 我”,“wo 喔”,这时以他们出现的顺序为序号区分,即“wo”这个拼音的第一个字是“我”,第二个字是“喔”。
输入拼音列表以单独的一行“end”结束。
接下来输入若干行询问的拼音,每行以“拼音 序号n”的形式输入,比如“wo 1”。
输入的询问拼音以单独的一行“end”结束。
Output
对于每一行输入询问的拼音,输出一个该拼音的第n个中文(如果n大于该拼音下的中文数,那么就输出该拼音下的最后一个中文)。
如果输入的拼音不存在之前的拼音列表中,则输出单独的一行"NO"。
Sample Input
wo 我
wo 喔
ni 你
ni 泥
end
wo 1
ni 3
ta 2
end
Sample Output
我
泥
NO
[查看全文]
Makefile.am:
终端输出:edm3 : main.o scene.o battlerbase.o battle.og++ -o edm3 main.o
main.o : main.cpp battlerbase.h scene.h
g++ -c main.cpp
scene.o : scene.cpp scene.h
g++ -c scene.cpp
battlerbase.o : battlerbase.cpp battlerbase.h
g++ -c battlerbase.cpp
battle.o : battle.cpp battle.h
g++ -c battle.cpp
clean :
rm main.o scene.o battlerbase.o battle.o
怀疑是不是文件名出了问题。。。[查看全文][otakuchiyan@localhost EDM3]$ tree -s.
├── [ 2005] Readme.txt
├── [ 649] battle.cpp
├── [ 439] battle.h
├── [ 496] battlerbase.cpp
├── [ 964] battlerbase.h
├── [ 7501] edm3
├── [ 51582] edm3tree.png
├── [ 620] main.cpp
├── [ 281] makefile.am
├── [ 631] scene.cpp
└── [ 638] scene.h
0 directories, 11 files
[otakuchiyan@localhost EDM3]$ make
make: *** ターゲットが指定されておらず, makefile も見つかりません. 中止.
[otakuchiyan@localhost EDM3]$ make makefile.am
make: `makefile.am' に対して行うべき事はありません.
[otakuchiyan@localhost EDM3]$ make makefile
make: *** ターゲット `makefile' を make するルールがありません. 中止.
[otakuchiyan@localhost EDM3]$ make makefile.am
make: `makefile.am' に対して行うべき事はありません.
[otakuchiyan@localhost EDM3]$ make
make: *** ターゲットが指定されておらず, makefile も見つかりません. 中止.
[otakuchiyan@localhost EDM3]$ make makefile
make: *** ターゲット `makefile' を make するルールがありません. 中止.
[otakuchiyan@localhost EDM3]$