Skip to content

Instantly share code, notes, and snippets.

@Abubakr0904
Created December 15, 2021 00:21
Show Gist options
  • Select an option

  • Save Abubakr0904/823e37e644c33393f39f7e1a1318ade5 to your computer and use it in GitHub Desktop.

Select an option

Save Abubakr0904/823e37e644c33393f39f7e1a1318ade5 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System.Linq;
using System;
public static class OJAnswers
{
public static void Problem51()
{
int n = int.Parse(Console.ReadLine());
int number = 1;
for(int i = 1; i <= n; i++)
{
int space = n - i;
while(space != 0)
{
Console.Write(" ");
space--;
}
int nums = i;
while(nums != 0)
{
Console.Write($"{number++ % 10} ");
nums--;
}
Console.WriteLine();
}
}
public static void Problem52()
{
int n = int.Parse(Console.ReadLine());
int sum = 0;
while(n != 0)
{
sum = sum + n % 10;
n /= 10;
if(n == 0 && sum > 9)
{
n = sum;
sum = 0;
}
}
Console.WriteLine($"{sum}");
}
public static void Problem53()
{
int count = 0;
int son = int.Parse(Console.ReadLine());
int temp = -10000000;
int sonCopy = son;
while(temp != sonCopy)
{
int son1 = son % 10;
int son2 = son / 10;
son = (son1 + son2) % 10;
int newson = son1 * 10 + son;
temp = newson;
son = newson;
count++;
}
Console.WriteLine($"{count}");
}
public static void Problem54()
{
var nums = Console.ReadLine().ToCharArray().Select(i => i.ToString()).ToList();
var counts = nums.GroupBy(i => i).Select(i => new {Num = i.ToList()[0], Count = i.Count()}).ToList();
foreach (var num in nums)
{
Console.Write($"{counts.Where(i => i.Num == num).ToList()[0].Count}");
}
}
public static void Problem55()
{
int count = 0;
int son = int.Parse(Console.ReadLine());
int reverseSon = int.Parse(new String(son.ToString().Reverse().ToArray()));
while(son != reverseSon)
{
son += reverseSon;
reverseSon = int.Parse(new String(son.ToString().Reverse().ToArray()));
count++;
}
Console.WriteLine($"{count} {son}");
}
public static void Problem56()
{
var str = Console.ReadLine().ToCharArray();
for(int i = 0; i < str.Length; i++)
{
for(int j = i; j < str.Length; j++)
{
if(str[j] == ' ')
{
continue;
}
if(str[j] < str[i])
{
var temp = str[i];
str[i] = str[j];
str[j] = temp;
}
}
}
Console.WriteLine($"{new String(str)}");
}
public static void Problem57()
{
int n = int.Parse(Console.ReadLine());
var list = Console.ReadLine().Split().Select(int.Parse).ToList();
list.Where(i => i >= list.Average()).ToList().ForEach(i => Console.Write($"{i} "));
Console.WriteLine();
}
public static void Problem58()
{
int n = int.Parse(Console.ReadLine());
var list = Console.ReadLine().Split().Select(int.Parse).ToList();
for(int i = 0; i < n - 1; i++)
{
if(list[i] > list[i + 1])
{
int temp = list[i];
list[i] = list[i + 1];
list[i + 1] = temp;
}
Console.WriteLine(list[i]);
}
Console.WriteLine(list[n - 1]);
}
public static void Problem59()
{
Console.ReadLine().Split().Select(int.Parse).ToList()
.GroupBy(i => i).ToList().ForEach(i =>
Console.WriteLine($"{i.Key}: {new String('*', i.Count())}"));
}
public static void Problem60()
{
var list = Console.ReadLine().Split().Select(int.Parse).ToList();
list.Sort();
Console.WriteLine($"{list[9]} {list[8]}");
}
public static void Problem61()
{
int n = int.Parse(Console.ReadLine()), count = 0;
string str = Console.ReadLine(), substr = "cat";
for(int i = 0; i < n - substr.Length + 1; i++)
{
var probableString = str.Substring(i, substr.Length);
if(probableString == substr)
count++;
}
Console.WriteLine($"{count}");
}
public static void Problem62()
{
int n = int.Parse(Console.ReadLine());
for(int i = 0; i < n; i++)
{
var temp = i.ToString().ToCharArray().Select(i => int.Parse(i.ToString())).ToList();
temp.Select(i => Math.Pow(i, temp.Count())).Sum();
if(temp.Select(i => Math.Pow(i, temp.Count())).Sum() == i)
{
Console.Write($"{i} ");
}
}
Console.WriteLine();
}
public static void Problem63()
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment