怎么做好一个网站,好的做网站,仿牌做外贸建网站,做网站排在前十名要多少钱26.寻找并输出11至999之间的数m#xff0c;它满足m,m2和m3均为回文数。所谓回文数是指其各位数字左右对称的整数#xff0c;例如121#xff0c;676#xff0c;94249等。满足上述条件的数如m11,m2121,m31331皆为回文数。请编制函数实现此功能#xff0c;如果是回文数#…26.寻找并输出11至999之间的数m它满足m,m2和m3均为回文数。所谓回文数是指其各位数字左右对称的整数例如12167694249等。满足上述条件的数如m11,m2121,m31331皆为回文数。请编制函数实现此功能如果是回文数则函数返回1反之则返回0。最后把结果输出。
27.键盘上任意输入一个十进制整数请编制函数将该整数转换成二进制数并把已转换的二进制数存放在字符串数组x中最后调用函数把结果输出。
28.用键盘输入一个16进制数并将该16进制数转换为二进制输出。
29.设有n个人围坐一圈并按顺时针方向从1到n编号从第s个人开始进行1到m的报数报数到第个m人此人出圈再从他的下一个人重新开始1到m的报数如此进行下去直到所有的人都出圈为止。现要求按出圈次序每10人一组输出这n个人的顺序表在控制台。
30.读取一篇英文文章存入到字符串数组x中请编制函数其功能是以行为单位对行中以空格或标点符号为分隔的所有单词进行倒排。最后把已处理的字符串(应不含标点符号)仍按行重新存入字符串数组x中最后调用函数把结果x输出。
例如原文 You He Me。 I am a student。 结果Me He You student a am I 26、首先定义一个函数是否是回文代码如下 27、我们要定义一个转换的方法代码如下
private static void Main(string[] args) { Console.WriteLine(请输入一个十进制整数); int s Convert.ToInt32(Console.ReadLine()); Console.WriteLine(二进制结果是 DecimalToBinary(s)); } public static string DecimalToBinary(int decimalNumber) { return Convert.ToString(decimalNumber, 2); } 28代码如下
Console.WriteLine(请输入16进制是: ); string hexNumber Console.ReadLine(); byte[] hexBytes new byte[hexNumber.Length / 2];
for (int i 0; i hexBytes.Length; i) { int index i * 2; hexBytes[i] Convert.ToByte(hexNumber.Substring(index, 2), 16); }
Console.WriteLine(16进制是: hexNumber); Console.WriteLine(二进制结果是: );
foreach (byte b in hexBytes) { string binaryString Convert.ToString(b, 2).PadLeft(8, 0); Console.WriteLine(binaryString); }
29、代码如下
private static void Main(string[] args) { Console.WriteLine(请输入总人数:); int n Convert.ToInt32(Console.ReadLine()); // 总人数 int s 1; // 开始报数的位置 int m 10; // 报数的间隔 Listint people new Listint(); for (int i 1; i n; i) { people.Add(i); // 初始化编号 } Listint result JosephusProblem(people, s, m); foreach (var id in result) { Console.WriteLine(id); // 输出出圈顺序 } }
static Listint JosephusProblem(Listint people, int s, int m) { Listint result new Listint(); // 存储出圈顺序的列表 while (people.Count 0) { int index s - 1; // 计算当前报数的位置数组索引从0开始 index index % people.Count; // 处理环形结构 result.Add(people[index]); // 将出圈的人添加到结果列表中 people.RemoveAt(index); // 从列表中移除该人 s; // 下一次报数从下一个人开始 if (s people.Count) s 1; // 如果s超过当前人数重置s为1 } return result; // 返回出圈顺序的列表 } 30、首先定义一个方法来过滤特殊字符数组进行倒序排列用到reserve方法代码如下
private static void Main(string[] args) { string article You He Me。 I am a student。; string[] words SplitArticleIntoWords(article); // 方法 Array.Reverse(words); // 倒序 foreach (string word in words) { Console.Write(word); // 输出 } }
static string[] SplitArticleIntoWords(string article) { char[] separators new char[] { , ., !, ?, ;, , ,。, }; // 过滤特殊字符 string[] words article.Split(separators, StringSplitOptions.RemoveEmptyEntries); return words; }