Code: Select all
List<int> l_reverse = lista;
Code: Select all
foreach (int x in lista)
l_reverse.Add(x);
l_reverse.Reverse();
Code: Select all
List<int> l_reverse = lista;
Code: Select all
foreach (int x in lista)
l_reverse.Add(x);
l_reverse.Reverse();
Easy. In difference with other languages, in C# you haven’t question for the EOF. You read while the input is distinct to null. The code is the next one:axlluis wrote: thanks bro, help mw with this please, if i have this input:
aaaaa
bbbbb
ccccc
ddddd
eeeee
How , can i get that information , if is not given the amount of lines that you have to read, (ends of file), please write the code to do this.
Code: Select all
string input = Console.Readline();
while(input != null)
{
input = Console.Readline();
}
Very easy too. I’ll show you 3 easy ways to do that(Sorting an array from major to minor):Another question, how can i use Comparison for sort a list?
Code: Select all
using System;
using System.Collections.Generic;
using System.Text;
namespace COJ
{
class Program
{
static void Main(string[] args)
{
int[] values = { 2, 6, 8, 9, 3, 5, 4, 34, 45, 7, 678, 79, 8, 99, 453, 42, 4, 32 };
Array.Sort<int>(values, (x, y) => y.CompareTo(x)); //First Way
Array.Sort<int>(values, new Comparison<int>(MajorMinor)); //Second Way
Array.Sort<int>(values, new CMP_Major_Minor()); //Third Way
}
class CMP_Major_Minor : Comparer<int>
{ public override int Compare(int x, int y) { return y.CompareTo(x); } }
static int MajorMinor(int x, int y) { return y.CompareTo(x); }
}
}
Code: Select all
a = [2, 6, 8, 9, 3, 5, 4, 34, 45, 7, 678, 79, 8, 99, 453, 42, 4, 32]
a.sort(lambda x, y:cmp(y, x))
Code: Select all
a = [2, 6, 8, 9, 3, 5, 4, 34, 45, 7, 678, 79, 8, 99, 453, 42, 4, 32]
a.sort! { |a1, a2| a2 <=> a1 }