Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = i;
}
return a;
for(int[] a=new int[n];n>0;a[n-1]=--n)if(n==1)return a;
int[] r = new int[n];
Array.ForEach(r, i => {if (i!=n-1) r[i+1]=i+1;});
return r;
int[] result = new int[n];
while((result[--n]=n)>0);
return result;
using System;
using System.Linq;
public class Program {
public static int[] Puzzle(int n) {
return Enumerable.Range(0, n).ToArray();
}
}
public class Program {
public static int Puzzle(int n) {
int result = 0;
for (int i=0; i<n;i++){
result = result + (i*i);
}
return result;
}
}
return s.Where(c => c == x).Count();
return s.Count(c => c == x);
(n-1)*n*(2*n-1)/6 дает меньше кирпичей?!Но пересчитав на калькуляторе по этой формуле, получаю 41,67. Что не так?
int. Только целые числа, только хардкор :)if(len < 4)
return "short";
if(len < 8)
return "average";
if(len < 15)
return "long";
return "super long";
return len < 4 ? "short" : len < 8 ? "average" : len < 15 ? "long" : "super long";
public static int Puzzle(int x) {
return String.valueOf(x).length();
}
public static int Puzzle(int x) {
return -x;
}
public static int Puzzle(int x) {
return -x;
}
public static int Puzzle(int x) {
return x*x;
}
public static int Puzzle(int x) {
return x*3;
}
public static int Puzzle(int x) {
return x/3;
}
public static int Puzzle(int x) {
return 4/x;
}
public static int Puzzle(int x, int y) {
return x-y;
}
public static int Puzzle(int x, int y) {
return x+2*y;
}
public static int Puzzle(int x, int y) {
return x*y;
}
public static int Puzzle(int x, int y) {
return x + y/3;
}
public static int Puzzle(int x, int y) {
return x / y;
}
public static int Puzzle(int x, int y) {
return x / y;
}
public static int Puzzle(int x) {
return (x % 3 + 1);
}
public static int Puzzle(int x) {
return 10 % x;
}
public static int Puzzle(int x, int y, int z) {
return (x+y+z)/3;
}
using System;
public class Program {
public static int Puzzle(int x) {
return x - 2;
}
}
using System;
public class Program {
public static int Puzzle(int x) {
return x % 3;
}
}
public static int[] Puzzle(int n) {
return Enumerable.Range(0, n).ToArray();
}
public static int[] Puzzle(int n) {
return Enumerable.Range(0, n).Select(x => x * n).ToArray();
}
public static int[] Puzzle(int n) {
return Enumerable.Range(0, n).Select(x => x * x).ToArray();
}
public static int Puzzle(int[] v) {
int sum = 0;
foreach (int e in v) {
sum += e;
}
return sum;
}
public static int Puzzle(int[] v) {
return v.Sum();
}
public static int Puzzle(int n) {
return (n-1)*(n)*(2*n-1)/6;
}
public static int Puzzle(string s) {
return (new Regex("[^a]")).Replace(s, "").Length;
}
public static int Puzzle(string s) {
return s.Count(c => 'a' == c);
}
public static int Puzzle(string s, char x) {
Regex rx = new Regex("[^" + x + "]");
return rx.Replace(s, "").Length;
}
public static int Puzzle(string s, char x) {
return s.Count(c => x == c);
}
int s = 0;
for (int i=0;i < v.Length;i++) s += v[i];
return s;
using System;
using System.Linq;
public class Program {
public static int Puzzle(int[] v) {
return unchecked((int)v.Sum(x => (long)x));
}
}
using System;
using System.Linq;
public class Program {
public static int Puzzle(int[] v) {
return v.Aggregate((x,y) => x+y);
}
}
using System;
using System.Linq;
public class Program {
public static int Puzzle(string s) {
return s.Length - s.Replace("a", "").Length;
}
}
using System;
using System.Linq;
public class Program {
public static int Puzzle(string s, char x) {
return s.Length - s.Replace(""+x, "").Length;
}
}
public static int Puzzle(int number, int power) {
return (int)Math.Pow(number, power);
}
public static int Puzzle(int number, int power) {
return Enumerable
.Range(0, power)
.Select(x => number)
.Aggregate(1, (i, j) => i*j);
}
public static int Puzzle(int i) {
return (i == 0)? 1: i * Puzzle(i-1);
}
public static int Puzzle(int lowerBound, int upperBound) {
int product = 1;
for (int i = lowerBound; i <= upperBound; ++i) {
product *= i;
}
return product;
}
public static int Puzzle(int n) {
return (n <= 0)? 0: (n+1) / 2 * ((n + 1) / 2 - 1);
}
public static int Puzzle(int n) {
return n*(n+1)*(n+2)/6;
}
public static string Puzzle(string word) {
return string.Join(" ", (new string('_', word.Length)).AsEnumerable());
}
public static string Puzzle(string s) {
return string.Join("",
s.Select(
c => (char)((c > 117)? (c - 21): (c + 5))
)
);
}
public static int Puzzle(int x) {
string s = "";
s += x;
return s.Length;
}
using System;
public class Program {
public static int Puzzle(int x) {
return x.ToString().Length;
}
}
public static int Puzzle(int a, int n)
{ return (n == 0)?1:(((n & 1) != 0)?a:1) * Puzzle(a * a, n / 2);}
using System;
using System;
public class Program {
public static int Puzzle(int a, int x) {
int b = 1;
for (; x>0; x/=2, a*=a)
if (x % 2 == 1) b *= a;
return b;
}
}
using System;
using System.Linq;
public class Program {
public static int Puzzle(int a, int n) {
return (int)(long)Math.Pow(a, n);
}
}
using System;
using System.Linq;
public class Program {
const int shift = 'f'-'a';
const int total = 'z'-'a'+1;
public static string Puzzle(string s) {
return string.Join("",
s.Select(
c => (char)((c-'a' + shift)%total + 'a')
));
}
}
using System;
public class Program {
public static int Puzzle(int number, int power) {
int res=1;
for(int i=0;i<power;i++) res*=number;
return res;
}
}
public static bool Puzzle(bool x, bool y) {
return x || y;
}
public static bool Puzzle(bool x, bool y) {
return x && y;
}
public static bool Puzzle(int x) {
return x < 50;
}
public static bool Puzzle(int x, int y) {
return x < y;
}
public static int Puzzle(int i) {
return (i == 0)? 0: Math.Abs(i)/i;
}
public static bool Puzzle(int i, int j) {
return true;
}
public static bool Puzzle(int i, int j) {
return false;
}
public static int Puzzle(int i) {
return (i < 100)? 2: 3;
}
public static string Puzzle(int i) {
return (i % 2 == 0)? "even": "odd";
}
public static string Puzzle(int i) {
return ((i % 5 == 0)? "": "not a ") + "multiple of 5";
}
public static string Puzzle(int i, int x) {
return ((i % x == 0)? "": "not a ") + ("multiple of " + x);
}
public static string Puzzle(int i, int j, int k) {
if (i / (double)j == j / (double)k && (i!=j)) return "yes!";
return "no";
}
public static int Puzzle(int i) {
if (i < 8) return 0;
if (i < 15) return 7;
return 21;
}
public static bool Puzzle(int i, int j) {
return i > j;
}
using System;
public class Program {
public static int Puzzle(int i) {
return Math.Sign(i);
}
}
using System;
public class Program {
public static string Puzzle(int i, int j, int k) {
return i==4*k && j==2*k ? "yes!" : "no";
}
}
return i < 50 ? 2 : 3;using System;
using System.Linq;
public class Program {
static int gcd(int a, int b) {
while (a>0) {
int c = b % a;
b = a;
a = c;
}
return b;
}
public static bool Puzzle(int a, int b, int c) {
return new[] { gcd(a,b), gcd(b,c), gcd(a,c) }.Distinct().Count() == 1
&& new[] {a,b,c}.Distinct().Count() == 3;
}
}
using System;
using System.Linq;
public class Program {
public static bool Puzzle(int a, int b, int c) {
int[] args = new[] {a,b,c};
return args.Distinct().Count() == 3
&& Enumerable.Range(1, Math.Max(Math.Max(a,b), c))
.All(d => args.Count(x => x%d==0) != 2);
}
}
(97, 41, 3) и (33, 1, 2) — в то время как первое … просто не проверяется на этих тестах! Эти два решения выдают совершенно одинаковые результаты — но первое проходит на два кирпича — а второе не проходит.
public static int fac(int i)
{
if (i == 1) return 1;
return i * fac(i - 1);
}
public static int Puzzle(int i, int j)
{
int sum = 0;
for (int k = i; k <= j; k++)
sum += fac(k);
return sum;
}
public static String Puzzle(String s) {
for (int i = 0; i < s.length(); i += 2) {
s = s.substring(0, i) + s.substring(i,i+1).toUpperCase() + s.substring(i+1)
}
return s;
}
public static String Puzzle(String s) {
char[] cb = s.toCharArray();
for (int i = 0; i < cb.length; i += 2) {
cb[i] = Character.toUpperCase(cb[i]);
}
return new String(cb);
}
public class Program {
public static int Puzzle(String s) {
return s.replaceAll("[^a]", "").length();
}
}
— ничуть не хороший код по сравнению с первым, и приветствовать такое — странно. Серьезный оверхед в виде использования регулярного выражения и создания новой строки там, где нужно просто посчитать символы 'a', ради экономии 3 строчек;
Microsoft Research запустила браузерную игру-головоломку по обучению программированию