1.字符串中有空格,处理使字符串,使不能有连续相连两格的空格,
写出思路,最好能用C#写出代码
2.用递归求出1到n的自然数的和
3.写一字符串,使输入e.a.cdfw
输出为VIM(e.a.cdfw)
dcaewf
写出思路,最好能用C#写出代码
2.用递归求出1到n的自然数的和
3.写一字符串,使输入e.a.cdfw
输出为VIM(e.a.cdfw)
dcaewf
调试欢乐多
{
// 第一个问题
string str = "aaa b dddddddddd ";
for( ; str.IndexOf( " " ) >= 0; str = str.Replace( " ", " " ) );
Console.WriteLine( str ); // 第二个问题
int n = 100; int result = 0;
sum( ref n, ref result );
Console.WriteLine( result ); } private void sum( ref int n, ref int result )
{
result += n;
if( n-- > 0 ) sum( ref n, ref result );
}以上在vs2003上测试通过。第三个问题不太明白,看样子是把字符串的里的点去掉,然后重排,可以把字符串变成字符数组,然后按给定的规则重排成新的字符串。
{
if (n > 0)
return n + add(n - 1);
return 0;
}