namespace 面试常见算法
{
class Program
{
static void Main(string[] args)
{
int n1 = Test1();
Console.WriteLine(n1); Test2(); Test3(); int n2 = Test4();
Console.WriteLine(n2); string s = Test5();
Console.WriteLine(s); Test6(); Test7(); Console.ReadKey();
} #region//1-2+3-4+...+m
static int Test1(int m)
{
int sum = ;
for (int i = ; i <= m; i++)
{
if (i % > ) //奇偶性判断
{
sum += i;
}
else
{
sum -= i;
}
}
return sum;
}
#endregion #region//1,2,3,4四个数字,能够组成多少互不相同无重复数字的三位数
static void Test2()
{
int count = ;
for (int bw = ; bw <= ; bw++)
{
for (int sw = ; sw <= ; sw++)
{
if (sw != bw)
{
for (int gw = ; gw <= ; gw++)
{
if (gw != sw && gw != bw)
{
count++;
Console.WriteLine("{0}{1}{2}", bw, sw, gw);
}
}
}
}
}
Console.WriteLine("一共有{0}个", count);
}
#endregion #region//12?56? * 123 = 154?4987
static void Test3()
{
for (int a = ; a < ; a++)
{
for (int b = ; b < ; b++)
{
for (int c = ; c < ; c++)
{
if (( + a + b * ) * == + c * )
{
Console.WriteLine(a);
Console.WriteLine(b);
Console.WriteLine(c);
}
}
}
}
}
#endregion #region//1 1 2 3 5 8 13 21 34...递归计算第30位数
static int Test4(int i)
{
if (i <= )
{
return ;
}
else if (i > && i <= )
{
return ;
}
else
{
return Test4(i - ) + Test4(i - );
}
}
#endregion #region//字符串反转
static string Test5()
{
string s = "I am a good man";
string[] arr = s.Split(' ');
string res = "";
for (int i = arr.Length - ; i >= ; i--)
{
res += arr[i];
if (i > )
res += " ";
}
return res;
}
#endregion #region//九九乘法表
static void Test6()
{
string t = string.Empty;
for (int i = ; i < ; i++)
{
for (int j = ; j <= i; j++)
{
t = string.Format("{0}*{1}={2} ", j, i, (j * i));
Console.Write(t);
if (i == j)
Console.Write("\n");
}
}
}
#endregion #region//冒泡排序 把一组数据按照从大到小/降序或从小到大/升序排列
static void Test7()
{
int[] nums = { , , , , , , , , , };
for (int i = ; i < nums.Length - ; i++)
{
for (int j = ; j < nums.Length - - i; j++)
{
if (nums[j] > nums[j + ])
{
int temp = nums[j];
nums[j] = nums[j + ]; //Array.Sort(nums);//升序
nums[j + ] = temp; //Array.Reverse(nums);//反转
}
}
}
for (int i = ; i < nums.Length; i++)
{
Console.Write(nums[i]);
}
}
#endregion }
}

原文链接:

https://blog.csdn.net/byondocean/article/details/7046101

最新文章

  1. Linux服务器安装笔记 汇总
  2. 将DataTable导出到Excel
  3. 基于 Ubuntu 编译 windows 版 adb
  4. smartlink
  5. Redis快速入门:安装、配置和操作
  6. zookeeper理论
  7. C++ Socket编程步骤 【转】
  8. vmwear 及docker
  9. 关于idea激活
  10. 关于java函数参数的修改能否带出来
  11. UVA - 699The Falling Leaves(递归先序二叉树)
  12. 屏蔽webbrowser控件右键的一种方法
  13. CodeForces 429B Working out 动态规划
  14. MFC中菜单的命令响应顺序
  15. OJ题:奇偶归一猜想——求归一过程中的最大值
  16. Python基础:数据类型-列表与元组(6)
  17. mysql 查询数据中文乱码
  18. keil在线烧录突然提示 No target connected #
  19. Ubuntu17.04下安装vmware虚拟机
  20. Delphi - 如何执行Windows、OSX、Linux的外部程序?

热门文章

  1. CAD制图系列之椭圆画法标注
  2. Java面试技巧—如何自我介绍
  3. 源码级别gdb远程调试(实现OS简单内核)
  4. Codeforces_101498
  5. Linux系统基础认知
  6. 转:JSON与Map互转
  7. linux使用和基础操作
  8. #614 C. NEKO&#39;s Maze Game[简易DFS,0|1转换]
  9. F——宋飞正传(HDU3351)
  10. codewars--js--counting duplicates