+ 1
How to reduce time of execution?
class Program { static void Main () { int number = int.Parse (Console.ReadLine ()); int S = 0, A = 0, P = 0, V = 0; for (int i = 0; i < number; i++) { V++; if (V == 4) { V = 0; P++; if (P == 4) { P = 0; A++; if (A == 3) { A = 0; S++; } } } } Console.WriteLine ("{0} {1} {2} {3}", S, A, P, V); }
2 Respostas
+ 1
you can remove the "A++;" and "P++;" parts and just modify the if statements to be "if(++P == 4)" and "if(++A == 3)" to make the code shorter too
0
I have already got it!
My solution
class Program {
static void Main () {
int number = int.Parse (Console.ReadLine ());
int S = 0, A = 0, P = 0, V = number % 4;
number = (number - V) / 4;
while (number != 0) {
P++;
if (P == 4) {
P = 0;
A++;
if (A == 3) {
A = 0;
S++;
}
}
number--;
}
Console.WriteLine ("{0} {1} {2} {3}", S, A, P, V);
}
}