- 001
- 002
- 003
- 004
- 005
- 006
- 007
- 008
- 009
- 010
- 011
- 012
- 013
- 014
- 015
- 016
- 017
- 018
- 019
- 020
- 021
- 022
- 023
- 024
- 025
- 026
- 027
- 028
- 029
- 030
- 031
- 032
- 033
- 034
- 035
- 036
- 037
- 038
- 039
- 040
- 041
- 042
- 043
- 044
- 045
- 046
- 047
- 048
- 049
- 050
- 051
- 052
- 053
- 054
- 055
- 056
- 057
- 058
- 059
- 060
- 061
- 062
- 063
- 064
- 065
- 066
- 067
- 068
- 069
- 070
- 071
- 072
- 073
- 074
- 075
- 076
- 077
- 078
- 079
- 080
- 081
- 082
- 083
- 084
- 085
- 086
- 087
- 088
- 089
- 090
- 091
- 092
- 093
- 094
- 095
- 096
- 097
- 098
- 099
- 100
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
/**
* Extension to simplify code writing
*/
static string Read()
{
return Console.ReadLine();
}
static void Print(string val, bool newline)
{
if(newline)
{
Console.WriteLine(val);
}
else
{
Console.Write(val);
}
}
static void Print(double val, bool newline)
{
if(newline)
{
Console.WriteLine(val.ToString());
}
else
{
Console.Write(val.ToString());
}
}
static void Print(bool val, bool newline)
{
if(newline)
{
Console.WriteLine(val.ToString());
}
else
{
Console.Write(val.ToString());
}
}
static void Print(int val, bool newline)
{
if(newline)
{
Console.WriteLine(val.ToString());
}
else
{
Console.Write(val.ToString());
}
}
/**
* End of extension
*/
static int ToBase(int number, int nbase = 2)
{
int converted = 0;
if(number == 0)
{
return 0;
}
else
{
while(number > 0)
{
converted = converted * 10 + (number % nbase);
number /= nbase;
}
}
return converted.ToString().Reverse().Aggregate(0, (b, x) => 10 * b + x - '0');
}
/** Use:
* The first number is the convertable
* The second is the base
*/
static void Main(string[] args)
{
int num = int.Parse(Read());
int nnbase = int.Parse(Read());
Print("The number is: ", false);
Print(num, true);
Print("The base is: ", false);
Print(nnbase, true);
Print("The conv. number is: ", false);
Print(ToBase(num, nnbase), true);
}
}
}