Documente Academic
Documente Profesional
Documente Cultură
Pe următoarele linii sunt numărul sau numerele pentru care se execută operația
(câte un număr pe linie).
Exemplul 1:
13
10110
11
La consolă se va afișa:
11001
Exemplul 2:
13
10
10
La consolă se va afișa:
100
using System;
namespace Sudoku
{
class Program
{
static void Main()
{
string operation = Console.ReadLine();
int op;
bool isOpNumeric = int.TryParse(operation, out op);
if (!isOpNumeric)
{
Console.WriteLine("Operatie invalida.");
}
else
{
string inputdata = Console.ReadLine();
ulong n;
int x = 0;
int z = 0;
int y = 0;
bool isNumeric = ulong.TryParse(inputdata, out n);
if (!isNumeric)
{
x++;
}
private static void FromBase2And10(ref int op, ref string inputdata, ref
int y, ref int z, string notbinar, ref ulong n, ref int x)
{
const int baseconvertor = 2;
int w = 0;
string binary = "";
x = 0;
foreach (char c in inputdata)
{
if (!(c >= '0' && c <= '9'))
{
x = 1;
}
}
while (op == 1 && x == 0)
{
if (n < 0)
{
Console.WriteLine("Programul converteste doar numere intregi
pozitive.");
x++;
z++;
}
else
{
binary = FromBase10(ref n, new[] { '0', '1' });
Console.WriteLine(binary);
x++;
z++;
}
}
do
{
result = baseChars[n % targetBase] + result;
n /= targetBase;
}
while (n > 0);
return result;
}
private static void Not(ref int op, ref string inputdata, ref int y, ref
int z, string notbinar)
{
int a = 3;
int w = 0;
while (op == a && z == 0)
{
IsBaza2(inputdata, ref w);
if (w != 0)
{
Console.WriteLine(notbinar);
op = a++;
y++;
z++;
}
else
{
JustOnes(inputdata, ref y, ref op, ref z, ref a);
}
}
}
b = c;
}
}
private static void JustOnes(string inputdata, ref int y, ref int op, ref
int z, ref int a)
{
int just1 = 0;
for (int i = 0; i < inputdata.Length; i++)
{
if (inputdata.Contains("0"))
{
just1++;
}
}
if (just1 == 0)
{
Console.WriteLine("0");
op = a++;
z++;
}
else
{
char[] element = { '0' };
string str1 = inputdata;
string str2 = "";
for (int n = 0; n < str1.Length; ++n)
{
str2 += (~(str1[n] - '0')) & 0x01;
}
private static void Or(ref int op, ref string inputdata, ref int y, ref int
z, ref ulong n, string notbinar)
{
int a = 4;
int w = 0;
while (z == 0 && op == a)
{
string secondnumber = Console.ReadLine();
IsBaza2(inputdata, ref w);
IsBaza2second(secondnumber, ref w);
if (w != 0)
{
Console.WriteLine(notbinar);
op = a++;
y++;
z++;
}
else
{
OrOperation(ref inputdata, ref secondnumber, ref n);
y++;
z++;
op = a++;
}
}
}
b = c;
}
}
Console.WriteLine(final);
}
}
private static void And(ref int op, ref string inputdata, ref int y, ref
int z, ref ulong n, string notbinar)
{
int a = 5;
int w = 0;
while (z == 0 && op == a)
{
string secondnumber = Console.ReadLine();
IsBaza2(inputdata, ref w);
IsBaza2second(secondnumber, ref w);
if (w != 0)
{
Console.WriteLine(notbinar);
op = a++;
y++;
z++;
}
else
{
AndOperation(ref inputdata, ref secondnumber, ref n);
y++;
z++;
op = a++;
}
}
}
Console.WriteLine(final);
}
}
private static void Xor(ref int op, ref string inputdata, ref int y, ref
int z, ref ulong n, string notbinar)
{
int a = 6;
int w = 0;
while (z == 0 && op == a)
{
string secondnumber = Console.ReadLine();
IsBaza2(inputdata, ref w);
IsBaza2second(secondnumber, ref w);
if (w != 0)
{
Console.WriteLine(notbinar);
op = a++;
y++;
z++;
}
else
{
Xoroperation(ref inputdata, ref secondnumber, ref n);
y++;
z++;
op = a++;
}
}
}
Console.WriteLine(final);
}
}
private static void ShiftLeftRifght(ref int op, string inputdata, ref int
y, ref int z, string notbinar)
{
int shiftleft = 7;
const int shiftright = 8;
int w = 0;
while (z == 0 && op == shiftleft || op == shiftright)
{
while (z == 0)
{
string shiftvalue = Console.ReadLine();
bool isInteger = int.TryParse(shiftvalue, out var result);
IsBaza2(inputdata, ref w);
if (w != 0)
{
Console.WriteLine(notbinar);
y++;
z++;
op = shiftleft--;
}
if (!isInteger)
{
Console.WriteLine("Numarul de pozitii trebuie sa fie intreg
si pozitiv.");
y++;
z++;
op = shiftleft--;
}
else if (result < 0)
{
Console.WriteLine("Numarul de pozitii trebuie sa fie intreg
si pozitiv.");
z++;
op = shiftleft--;
}
if (z == 0)
{
ShiftOperation(inputdata, shiftvalue, shiftleft,
shiftright, op);
y++;
z++;
op = shiftleft--;
}
}
}
}
Console.WriteLine(inputdata + addzero);
}
private static void Comparison(ref int op, string inputdata, ref int y, ref
int z, string notbinar)
{
const string falseresult = "False";
const string trueresult = "True";
Lessthan(ref op, inputdata, ref y, ref z, notbinar, falseresult,
trueresult);
GreaterThan(ref op, inputdata, ref y, ref z, notbinar, falseresult,
trueresult);
Equal(ref op, inputdata, ref y, ref z, notbinar, falseresult,
trueresult);
NotEqual(ref op, inputdata, ref y, ref z, notbinar, falseresult,
trueresult);
}
private static void Lessthan(ref int op, string inputdata, ref int y, ref
int z, string notbinar, string falseresult, string trueresult)
{
int lessthan = 9;
char[] element = { '0' };
int w = 0;
while (z == 0 && op == lessthan)
{
string secondnumber = Console.ReadLine();
string inputnozero = inputdata.TrimStart(element);
string secondnozero = secondnumber.TrimStart(element);
IsBaza2(inputdata, ref w);
if (w != 0)
{
Console.WriteLine(notbinar);
y++;
z++;
}
if (inputnozero.Length != secondnozero.Length)
{
if (inputnozero.Length > secondnozero.Length)
{
z++;
y++;
op = lessthan--;
Console.WriteLine(falseresult);
}
else
{
z++;
y++;
op = lessthan--;
Console.WriteLine(trueresult);
}
}
else if (z == 0)
{
EqualNumbers(inputnozero, secondnozero, op, falseresult,
trueresult);
z++;
y++;
op = lessthan--;
}
}
}
private static void GreaterThan(ref int op, string inputdata, ref int y,
ref int z, string notbinar, string falseresult, string trueresult)
{
int greaterthan = 10;
char[] element = { '0' };
int w = 0;
while (z == 0 && op == greaterthan)
{
string secondnumber = Console.ReadLine();
string inputnozero = inputdata.TrimStart(element);
string secondnozero = secondnumber.TrimStart(element);
IsBaza2(inputdata, ref w);
if (w != 0)
{
Console.WriteLine(notbinar);
y++;
z++;
}
if (inputnozero.Length != secondnozero.Length)
{
if (inputnozero.Length > secondnozero.Length)
{
z++;
y++;
op = greaterthan--;
Console.WriteLine(trueresult);
}
else
{
z++;
y++;
op = greaterthan--;
Console.WriteLine(falseresult);
}
}
else
{
EqualNumbers(inputnozero, secondnozero, op, falseresult,
trueresult);
z++;
y++;
op = greaterthan--;
}
}
}
private static void Equal(ref int op, string inputdata, ref int y, ref int
z, string notbinar, string falseresult, string trueresult)
{
int equal = 11;
char[] element = { '0' };
int w = 0;
while (z == 0 && op == equal)
{
string secondnumber = Console.ReadLine();
string inputnozero = inputdata.TrimStart(element);
string secondnozero = secondnumber.TrimStart(element);
IsBaza2(inputdata, ref w);
if (w != 0)
{
Console.WriteLine(notbinar);
y++;
z++;
}
else
{
EqualNumbers(inputnozero, secondnozero, op, falseresult,
trueresult);
z++;
y++;
op = equal--;
}
}
}
private static void NotEqual(ref int op, string inputdata, ref int y, ref
int z, string notbinar, string falseresult, string trueresult)
{
int notequal = 12;
char[] element = { '0' };
int w = 0;
while (z == 0 && op == notequal)
{
string secondnumber = Console.ReadLine();
string inputnozero = inputdata.TrimStart(element);
string secondnozero = secondnumber.TrimStart(element);
IsBaza2(inputdata, ref w);
if (w != 0)
{
Console.WriteLine(notbinar);
y++;
z++;
}
else
{
EqualNumbers(inputnozero, secondnozero, op, falseresult,
trueresult);
z++;
y++;
op = notequal--;
}
}
}
if (i == inputnozero.Length - 1)
{
Console.WriteLine(falseresult);
}
}
}
if (i == inputnozero.Length - 1)
{
Console.WriteLine(falseresult);
}
}
}
if (i == inputnozero.Length - 1)
{
Console.WriteLine(trueresult);
}
}
}
if (i == inputnozero.Length - 1)
{
Console.WriteLine(falseresult);
}
}
}
private static void BinarSum(ref int op, string inputdata, ref int y, ref
int z, string notbinar)
{
int binarsum = 13;
int w = 0;
int k = 0;
while (z == 0 && op == binarsum)
{
while (z == 0)
{
string secondnumber = Console.ReadLine();
secondnumber = secondnumber.Replace(" ", "");
inputdata = inputdata.Replace(" ", "");
IsBaza2(inputdata, ref w);
if (w != 0)
{
Console.WriteLine(notbinar);
y++;
z++;
k = w;
op = binarsum--;
}
if (z == 0)
{
BinarSumOperation(inputdata, secondnumber);
y++;
z++;
op = binarsum--;
}
}
}
}
int j = newinputdata.Length - 1;
while (j >= 0)
{
if (carryover == "0")
{
Nocarryover(ref result, newsecondnumber, newinputdata, ref
carryover, j, ref final);
j--;
}
Console.WriteLine(final);
}
while (whilecontrol == 0)
{
if (newinputdata[j] == '0')
{
const string element = "0";
result = element + result;
carryover = "0";
whilecontrol++;
final = result.TrimStart(zero);
}
if (newinputdata[j] == '1')
{
const string element = "0";
result = element + result;
carryover = "1";
whilecontrol++;
final = result.TrimStart(zero);
}
}
}
while (whilecontrol == 0)
{
if (newinputdata[j] == '0')
{
const string element = "1";
result = element + result;
carryover = "0";
whilecontrol++;
final = result.TrimStart(zero);
}
if (newinputdata[j] == '1')
{
const string element = "1";
result = element + result;
carryover = "1";
whilecontrol++;
final = result.TrimStart(zero);
}
}
}