C#

Discussion on other languages at the COJ. This is the place to clear your doubts about these languages, and to share with the community the new things you learn about them.
axlluis
Posts: 17
Joined: 6 years ago
Gender: None specified

C#

Post by axlluis » 6 years ago

For the ones who prefers this lenguage. I start with the first question can someone show me how to work with |N| in c# please, any funtion of c# method or something??



User avatar
Phantom
Posts: 58
Joined: 7 years ago
Location: Cuba
Gender: None specified

Re: C#

Post by Phantom » 6 years ago

Ok, C#, good idea, I like this language too, no many as Python and Ruby, but I like it. I can say this is the language in where I am better. If you know something about C, C++ or Java, C# will be very easy for you. C# is upswing of the languages before mentioned. If you want I teach you C#, I’ll do this. But… I recommend Python and Ruby :D.

This is an integer in C#:
int pepe = 50; //(like C, C++ and Java…)
An “int” have 32 bits, a “long” have 64, a “short” have 16, and a “bit”… (obvious)
Now is 2:00 am… another day I’ll follow. Good Nigth.
(The forum clock is bad)

axlluis
Posts: 17
Joined: 6 years ago
Gender: None specified

Re: C#

Post by axlluis » 6 years ago

Hi phantom, i need your help, in the problem "1382 - Sum of Cubes" and in others too, the result most given in mod 1000007, i dont understand what that means and how to do it in c#, i have the algorithm for the problem but i dont know how to do de mod 1000007 thing, can you help me please?

User avatar
Phantom
Posts: 58
Joined: 7 years ago
Location: Cuba
Gender: None specified

Re: C#

Post by Phantom » 6 years ago

Very easy, modulus (mod) is like in almost every language:

int mod = 5 % 3; //Now mod have the value 2

mod = 13 % 5; //Now mod have the value 3

m = pq + r
The function modulus (%) returns “r”.
13 = 5*2 + 3

axlluis
Posts: 17
Joined: 6 years ago
Gender: None specified

Re: C#

Post by axlluis » 6 years ago

Thanks bro, i do what you tell me but for the last case steel give me a wrong answer, the problem is "1382 - Sum of Cubes", for the two first cases give the right answer but in the last case, give me a negative value when the right is 441. please help me with that.

Ejemplo de entrada

3
1 10
27 27
1 1000000000000000000

Ejemplo de salida

9
27
441

User avatar
Phantom
Posts: 58
Joined: 7 years ago
Location: Cuba
Gender: None specified

Re: C#

Post by Phantom » 6 years ago

Your problem is not in C#. Your Problem is in your implementation. When you are adding in an integer, and in a certain moment the value of your integer is negative, is because this integer is out of range. When an integer, double, long, etc… exceed its maximum value, it take its minimum value, like a loop. In your implementation, you are not using very well the modulus operator (%) or you are not putting it in the places it must be.

User avatar
Robbin
Posts: 38
Joined: 7 years ago
Location: Santiago de Cuba
Gender: None specified

Re: C#

Post by Robbin » 6 years ago

May be the problem is the entry..
may be the data type is too long dor the supported by c++
I suggest you to make this program in python..or java..

axlluis
Posts: 17
Joined: 6 years ago
Gender: None specified

Re: C#

Post by axlluis » 6 years ago

You have reason, my problem is not in c sharp, but i wrote in the problem set my questions and nobody answer me, and i take the chance that you help me with c sharp for make you this question.
Well, can any boy explain me what for 1 1000000000000000000 the result is 441??

User avatar
Phantom
Posts: 58
Joined: 7 years ago
Location: Cuba
Gender: None specified

Re: C#

Post by Phantom » 6 years ago

Look, if you want help for your solutions, you can post in the topic "Problem set". This topic most be to talk only about C#.
Last edited by Phantom on Thu Jun 28, 2012 3:23 pm, edited 1 time in total.

axlluis
Posts: 17
Joined: 6 years ago
Gender: None specified

Re: C#

Post by axlluis » 6 years ago

you are right lets talk about c-sharp so, in this code:

Code: Select all

 string[] info = Console.ReadLine().Split();
            List<int> lista = new List<int>();
            foreach (string x in info)
            {
                lista.Add(int.Parse(x));
            }
            lista.Sort();
            List<int> l_reverse = lista;
            l_reverse.Reverse(); 
Why reverse==lista, what i want is have the sort list in ascending order in "lista" and in descending order in "l_reverse", but the C# when i do " l_reverse.Reverse()" make to lista equal to l_reverse. Can someone help me?

Post Reply

Return to “Other languages”