vector<string> v={ "张三","李四", "王五", "赵六", "田七", "周八", "吴九" };
时间: 2023-08-10 09:03:06 浏览: 157
感谢您提供的信息!根据您给出的代码,您创建了一个名为"v"的vector<string>对象,并初始化了一些字符串元素。这个vector中包含了一些人名,包括"张三"、"李四"、"王五"等等。您是否有关于这个vector的具体问题或者需要我帮助您进行某些操作呢?请告诉我您需要的帮助或者具体问题,我会尽力回答。
相关问题
写随机点名的程序,抽取三个人名,并且进行控制台输出。 1班有八个人,"张三","李四","王五","赵六","孙七","周八","吴九","郑十" 2班有八个人,"张三2","李四2","王五2","赵六2","孙七2","周八2","吴九2","郑十2"
可以使用Random类来实现随机点名程序,具体实现如下:
```csharp
using System;
namespace RandomName
{
class Program
{
static void Main(string[] args)
{
string[] class1 = { "张三", "李四", "王五", "赵六", "孙七", "周八", "吴九", "郑十" };
string[] class2 = { "张三2", "李四2", "王五2", "赵六2", "孙七2", "周八2", "吴九2", "郑十2" };
Random random = new Random();
int index1 = random.Next(0, class1.Length);
int index2 = random.Next(0, class2.Length);
int index3 = random.Next(0, class1.Length);
Console.WriteLine("抽取的三个人名为:");
Console.WriteLine(class1[index1]);
Console.WriteLine(class2[index2]);
Console.WriteLine(class1[index3]);
Console.ReadKey();
}
}
}
```
以上代码中,我们首先定义了两个班级的学生名单,然后使用Random类生成三个随机数,分别对应三个被抽取的学生的下标。最后将这三个学生名字输出到控制台上。
写随机点名的程序,抽取三个人名,并且进行控制台输出。 1班有八个人,"张三","李四","王五","赵六","孙七","周八","吴九","郑十" 2班有八个人,"张三2","李四2","王五2","赵六2","孙七2","周八2","吴九2","郑十2",用c#
以下是用C#编写的随机点名程序,抽取三个人名并进行控制台输出:
```csharp
using System;
using System.Collections.Generic;
namespace RandomName
{
class Program
{
static void Main(string[] args)
{
// 初始化班级名单
List<string> class1 = new List<string>() { "张三", "李四", "王五", "赵六", "孙七", "周八", "吴九", "郑十" };
List<string> class2 = new List<string>() { "张三2", "李四2", "王五2", "赵六2", "孙七2", "周八2", "吴九2", "郑十2" };
// 从班级名单中随机抽取三个人
List<string> selectedNames = new List<string>();
Random random = new Random();
int class1Count = class1.Count;
int class2Count = class2.Count;
int selectedCount = 0;
while (selectedCount < 3)
{
int classIndex = random.Next(2);
List<string> selectedClass = classIndex == 0 ? class1 : class2;
int nameIndex = random.Next(selectedClass.Count);
string selectedName = selectedClass[nameIndex];
if (!selectedNames.Contains(selectedName))
{
selectedNames.Add(selectedName);
selectedCount++;
}
}
// 输出抽取的三个人名
Console.WriteLine("抽取的三个人名为:");
foreach (string name in selectedNames)
{
Console.WriteLine(name);
}
}
}
}
```
阅读全文