问题陈述 - 无法理解问题的措辞
Problem statement-Unable to understand wording of the problem
我正在尝试编写代码以改进我的编码 skills.I 遇到了问题,但我不确定问题陈述是什么 is.Can 有人帮助理解 problem.I 会相应地编写代码。
无人机舰队
问题陈述
你得到了一队无人机。
无人机排成一排,用字符>和<表示。 > 表示无人机指向前方,< 表示无人机指向后方。操作员控制车队可以执行多项操作。一个操作使用起始位置索引和结束位置索引,它重新定位落在索引之间的所有无人机(包括索引本身)。 objective是输出无人机的最终状态。
输入格式
输入的第一行包含一个整数t,表示测试用例的数量。每个测试用例的第一行由一个整数 n 组成,表示无人机的数量。第二行是n个无人机的方位表示。第三行包含一个整数 o,表示操作数。接下来的 o 行,每行由两个 space 分隔的整数 s(表示开始索引)和 e(表示结束索引)组成。索引从0开始。
示例输入
3
4
<<<<
1
0 2
2
<>
0
5
'><<<<'
5
0 2
1 2
0 2
0 4
3 3
示例输出:
'>>><'
<>
<<><>
您需要将其分解并一点一点地完成,并通读说明以确保您理解。我已经记录了每一行并说明了它是什么以及下面每个测试用例的每个操作的结果。
3 = Number of Test Cases
== Test case 1 ==
4 = Number of drones
<<<< = Start orientation of each drone (4 as per line above)
1 = Number of operations
== Operation 1 of Test case 1 ==
0 2 = Start & end index
== Result of Test case 1 ==
>>><
== Test case 2 ==
2 = Number of drones
<> = Start orientation of each drone
0 = Number of operations
== Result of Test case 2 ==
<>
== Test case 3 ==
5 = Number of drones
><<<< = Start orientation of each drone
5 = Number of operations
== Operation 1 of Test case 3 ==
0 2 = Start & end index
== Operation 2 of Test case 3 ==
1 2 = Start & end index
== Operation 3 of Test case 3 ==
0 2 = Start & end index
== Operation 4 of Test case 3 ==
0 4 = Start & end index
== Operation 5 of Test case 3 ==
3 3 = Start & end index
== Result of Test case 2 ==
<>><< = after operation 1
<<<<< = after operation 2
>><<< = after operation 3
<<>>> = after operation 4
<<><> = after operation 5 (result)
using System;
using System.Collections.Generic;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter number of Test cases");
int testcases = Convert.ToInt32(Console.ReadLine());
for(int k=1;k<=testcases;k++)
{
Console.Write("Enter number of drones for {0} test case",k);
int numofdrones = Convert.ToInt32(Console.ReadLine());
Console.Write("enter the orientaion for {0} drones as < or > ", numofdrones);
string dronesOrientaion = Console.ReadLine();
Console.Write("Enter number of operation required for {0} test case", k);
int numOperation = Convert.ToInt32(Console.ReadLine());
Dictionary<int, List<int>> indexofoperation = new Dictionary<int, List<int>>();
for (int i = 1; i <= numOperation; i++)
{
List < int > indexval= new List<int>();
Console.WriteLine("enter start index");
int startindex = Convert.ToInt32(Console.ReadLine());
indexval.Add(startindex);
Console.WriteLine("enter end index");
int endindex = Convert.ToInt32(Console.ReadLine());
indexval.Add(endindex);
indexofoperation.Add(i, indexval);
}
finalDroneState(dronesOrientaion, indexofoperation);
Console.ReadLine();
}
}
private static void finalDroneState(string dronesOrientaion, Dictionary<int, List<int>> indexofoperation)
{
string initialString = dronesOrientaion;
foreach (var item in indexofoperation)
{
//for (int a = 0; a < item.Key; a++)
//{
List<int> operationval = item.Value;
int[] arr1 = operationval.ToArray();
for (int s=arr1[0];s<=arr1[arr1.Length-1];s++)//each (int m in operationval)
{
char[] ch = initialString.ToCharArray();
if (ch[s] == '>')
{
ch[s] = '<';
}
else
{
ch[s] = '>';
}
initialString = new string(ch);
}
// }
}
Console.WriteLine(initialString);
}
}
}
我正在尝试编写代码以改进我的编码 skills.I 遇到了问题,但我不确定问题陈述是什么 is.Can 有人帮助理解 problem.I 会相应地编写代码。 无人机舰队
问题陈述
你得到了一队无人机。
无人机排成一排,用字符>和<表示。 > 表示无人机指向前方,< 表示无人机指向后方。操作员控制车队可以执行多项操作。一个操作使用起始位置索引和结束位置索引,它重新定位落在索引之间的所有无人机(包括索引本身)。 objective是输出无人机的最终状态。
输入格式
输入的第一行包含一个整数t,表示测试用例的数量。每个测试用例的第一行由一个整数 n 组成,表示无人机的数量。第二行是n个无人机的方位表示。第三行包含一个整数 o,表示操作数。接下来的 o 行,每行由两个 space 分隔的整数 s(表示开始索引)和 e(表示结束索引)组成。索引从0开始。
示例输入
3
4
<<<<
1
0 2
2
<>
0
5
'><<<<'
5
0 2
1 2
0 2
0 4
3 3
示例输出:
'>>><'
<>
<<><>
您需要将其分解并一点一点地完成,并通读说明以确保您理解。我已经记录了每一行并说明了它是什么以及下面每个测试用例的每个操作的结果。
3 = Number of Test Cases
== Test case 1 ==
4 = Number of drones
<<<< = Start orientation of each drone (4 as per line above)
1 = Number of operations
== Operation 1 of Test case 1 ==
0 2 = Start & end index
== Result of Test case 1 ==
>>><
== Test case 2 ==
2 = Number of drones
<> = Start orientation of each drone
0 = Number of operations
== Result of Test case 2 ==
<>
== Test case 3 ==
5 = Number of drones
><<<< = Start orientation of each drone
5 = Number of operations
== Operation 1 of Test case 3 ==
0 2 = Start & end index
== Operation 2 of Test case 3 ==
1 2 = Start & end index
== Operation 3 of Test case 3 ==
0 2 = Start & end index
== Operation 4 of Test case 3 ==
0 4 = Start & end index
== Operation 5 of Test case 3 ==
3 3 = Start & end index
== Result of Test case 2 ==
<>><< = after operation 1
<<<<< = after operation 2
>><<< = after operation 3
<<>>> = after operation 4
<<><> = after operation 5 (result)
using System;
using System.Collections.Generic;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter number of Test cases");
int testcases = Convert.ToInt32(Console.ReadLine());
for(int k=1;k<=testcases;k++)
{
Console.Write("Enter number of drones for {0} test case",k);
int numofdrones = Convert.ToInt32(Console.ReadLine());
Console.Write("enter the orientaion for {0} drones as < or > ", numofdrones);
string dronesOrientaion = Console.ReadLine();
Console.Write("Enter number of operation required for {0} test case", k);
int numOperation = Convert.ToInt32(Console.ReadLine());
Dictionary<int, List<int>> indexofoperation = new Dictionary<int, List<int>>();
for (int i = 1; i <= numOperation; i++)
{
List < int > indexval= new List<int>();
Console.WriteLine("enter start index");
int startindex = Convert.ToInt32(Console.ReadLine());
indexval.Add(startindex);
Console.WriteLine("enter end index");
int endindex = Convert.ToInt32(Console.ReadLine());
indexval.Add(endindex);
indexofoperation.Add(i, indexval);
}
finalDroneState(dronesOrientaion, indexofoperation);
Console.ReadLine();
}
}
private static void finalDroneState(string dronesOrientaion, Dictionary<int, List<int>> indexofoperation)
{
string initialString = dronesOrientaion;
foreach (var item in indexofoperation)
{
//for (int a = 0; a < item.Key; a++)
//{
List<int> operationval = item.Value;
int[] arr1 = operationval.ToArray();
for (int s=arr1[0];s<=arr1[arr1.Length-1];s++)//each (int m in operationval)
{
char[] ch = initialString.ToCharArray();
if (ch[s] == '>')
{
ch[s] = '<';
}
else
{
ch[s] = '>';
}
initialString = new string(ch);
}
// }
}
Console.WriteLine(initialString);
}
}
}