C#程序算法

来源:百度知道 编辑:UC知道 时间:2024/05/21 18:59:11
1、有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位。

2、用1、2、2、3、4、5这六个数字,写程序打印出所有不同的排列,如:512234、412345等,要求:"4"不能在第三位,"3"的右边不能是"5"。

用C#实现

//问题一
using System;
using System.Collections.Generic;
using System.Text;

namespace qq82085166
{
class Program
{

static void Main(string[] args)
{
Console.WriteLine("请输入人数");
int n = Convert.ToInt32(Console.ReadLine()); //人数
int i; //序号
int[] ywz = new int[n];
for (i = 1; i <= n; i++)
{
ywz[i - 1] = i; //ywz[i - 1]为原来的位置;
Console.WriteLine("序号{0},原来的位置{1}", i, ywz[i - 1]);
}
for (int j = 1; j <= n; j++)
{
if (j % 3 == 0 && j > 2)
{
ywz[j - 1] = -1;
Console.WriteLine("出去的: 原序号{0},现在的位置{1}", j, ywz[j - 1]); //-1表示要站出来的人的序号;