Created
April 6, 2023 16:34
-
-
Save kareiva/9a4a37a69b43fe80d1a89840b0a7878b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#xxxxxxxxxxxxx IT 2 kursas 1 grupë 2013 m. ruduo | |
#/bin/bash | |
hex=16 | |
echo "Pasirinkite veiksma:" | |
echo "1. Sesioliktainis_sk = Desimtainis_sk" | |
echo "2. Desimtainis_sk = Sesioliktainis_sk" | |
echo "3. Baigti darba" | |
read number | |
if [ -z $number ] | |
then | |
echo "Komanda nebuvo ivesta!" | |
else | |
if [ $number = "1" ] | |
then | |
echo "Iveskite 16-taini skaiciu:" | |
read sesioliktainis | |
p=0 | |
len=`expr length $sesioliktainis` | |
for ((i=0; i<len; i++)) | |
do | |
MAS[$i]=${sesioliktainis:p:1} | |
p=`expr $p + 1` | |
done | |
arrLen=${#MAS[*]} | |
for ((i=0; i<arrLen; i++)) | |
do | |
if [ ${MAS[$i]} = "A" ] | |
then | |
MAS[$i]="10" | |
else | |
if [ ${MAS[$i]} = "B" ] | |
then | |
MAS[$i]="11" | |
else | |
if [ ${MAS[$i]} = "C" ] | |
then | |
MAS[$i]="12" | |
else | |
if [ ${MAS[$i]} = "D" ] | |
then | |
MAS[$i]="13" | |
else | |
if [ ${MAS[$i]} = "E" ] | |
then | |
MAS[$i]="14" | |
else | |
if [ ${MAS[$i]} = "F" ] | |
then | |
MAS[$i]="15" | |
else | |
if [ ${MAS[$i]} = "a" ] | |
then | |
MAS[$i]="10" | |
else | |
if [ ${MAS[$i]} = "b" ] | |
then | |
MAS[$i]="11" | |
else | |
if [ ${MAS[$i]} = "c" ] | |
then | |
MAS[$i]="12" | |
else | |
if [ ${MAS[$i]} = "d" ] | |
then | |
MAS[$i]="13" | |
else | |
if [ ${MAS[$i]} = "e" ] | |
then | |
MAS[$i]="14" | |
else | |
if [ ${MAS[$i]} = "f" ] | |
then | |
MAS[$i]="15" | |
else | |
if [ ${MAS[$i]} == "G" ] || | |
[ ${MAS[$i]} == "H" ] || | |
[ ${MAS[$i]} == "I" ] || | |
[ ${MAS[$i]} == "J" ] || | |
[ ${MAS[$i]} == "K" ] || | |
[ ${MAS[$i]} == "L" ] || | |
[ ${MAS[$i]} == "M" ] || | |
[ ${MAS[$i]} == "N" ] || | |
[ ${MAS[$i]} == "O" ] || | |
[ ${MAS[$i]} == "P" ] || | |
[ ${MAS[$i]} == "Q" ] || | |
[ ${MAS[$i]} == "R" ] || | |
[ ${MAS[$i]} == "S" ] || | |
[ ${MAS[$i]} == "T" ] || | |
[ ${MAS[$i]} == "U" ] || | |
[ ${MAS[$i]} == "V" ] || | |
[ ${MAS[$i]} == "W" ] || | |
[ ${MAS[$i]} == "X" ] || | |
[ ${MAS[$i]} == "Y" ] || | |
[ ${MAS[$i]} == "Z" ] || | |
[ ${MAS[$i]} == "g" ] || | |
[ ${MAS[$i]} == "h" ] || | |
[ ${MAS[$i]} == "i" ] || | |
[ ${MAS[$i]} == "j" ] || | |
[ ${MAS[$i]} == "k" ] || | |
[ ${MAS[$i]} == "l" ] || | |
[ ${MAS[$i]} == "m" ] || | |
[ ${MAS[$i]} == "n" ] || | |
[ ${MAS[$i]} == "o" ] || | |
[ ${MAS[$i]} == "p" ] || | |
[ ${MAS[$i]} == "q" ] || | |
[ ${MAS[$i]} == "r" ] || | |
[ ${MAS[$i]} == "s" ] || | |
[ ${MAS[$i]} == "t" ] || | |
[ ${MAS[$i]} == "u" ] || | |
[ ${MAS[$i]} == "v" ] || | |
[ ${MAS[$i]} == "w" ] || | |
[ ${MAS[$i]} == "x" ] || | |
[ ${MAS[$i]} == "y" ] || | |
[ ${MAS[$i]} == "z" ] | |
then | |
echo "Neteisingas 16-tainis skaicius!" | |
exit 0 | |
fi | |
fi | |
fi | |
fi | |
fi | |
fi | |
fi | |
fi | |
fi | |
fi | |
fi | |
fi | |
fi | |
done | |
for ((i=1; i<arrLen+1; i++)) | |
do | |
midValue=$(($arrLen-$i)) | |
hexValue=1 | |
for ((o=0; o<$midValue; o++)) | |
do | |
hexValue=$(($hexValue*$hex)) | |
done | |
DecAnswer[($i-1)]=$((${MAS[($i-1)]}*$hexValue)) | |
done | |
for ((i=0; i<${#DecAnswer[@]}; i++)) | |
do | |
answer=$(($answer+${DecAnswer[$i]})) | |
done | |
echo "Skaicius 10-taineje sistemoje:" | |
echo "$answer" | |
exit 0 | |
else | |
if [ $number = "2" ] | |
then | |
echo "Iveskite 10-taini skaiciu:" | |
read desimtainis | |
i=0 | |
o=0 | |
for ((no=$desimtainis; $desimtainis>=$hex; desimtainis=o)) | |
do | |
MOD[$i]=`expr $desimtainis % $hex` | |
DIV[$i]=`expr $desimtainis / $hex` | |
o=${DIV[$i]} | |
i=`expr $i + 1` | |
done | |
count=${#MOD[*]} | |
countDiv=${#DIV[*]} | |
for ((i=0; i<$count; i++)) | |
do | |
if [ ${MOD[$i]} = "10" ] | |
then | |
MOD[$i]="A" | |
else | |
if [ ${MOD[$i]} = "11" ] | |
then | |
MOD[$i]="B" | |
else | |
if [ ${MOD[$i]} = "12" ] | |
then | |
MOD[$i]="C" | |
else | |
if [ ${MOD[$i]} = "13" ] | |
then | |
MOD[$i]="D" | |
else | |
if [ ${MOD[$i]} = "14" ] | |
then | |
MOD[$i]="E" | |
else | |
if [ ${MOD[$i]} = "15" ] | |
then | |
MOD[$i]="F" | |
fi | |
fi | |
fi | |
fi | |
fi | |
fi | |
if [ ${DIV[$i]} = "10" ] | |
then | |
DIV[$i]="A" | |
else | |
if [ ${DIV[$i]} = "11" ] | |
then | |
DIV[$i]="B" | |
else | |
if [ ${DIV[$i]} = "12" ] | |
then | |
DIV[$i]="C" | |
else | |
if [ ${DIV[$i]} = "13" ] | |
then | |
DIV[$i]="D" | |
else | |
if [ ${DIV[$i]} = "14" ] | |
then | |
DIV[$i]="E" | |
else | |
if [ ${DIV[$i]} = "15" ] | |
then | |
DIV[$i]="F" | |
fi | |
fi | |
fi | |
fi | |
fi | |
fi | |
done | |
if [ $countDiv != "0" ] | |
then | |
Answer[0]=${DIV[($countDiv-1)]} | |
for ((i=1; i<=$count; i++)) | |
do | |
Answer[i]=${MOD[($count-i)]} | |
done | |
string=$(printf "%s" "${Answer[@]}") | |
echo "Skaicius 16-taineje sistemoje:" | |
echo "$string" | |
exit 0 | |
else | |
if [ $countDiv -eq 0 ] | |
then | |
if [ $desimtainis = "10" ] | |
then | |
echo "Skaicius 16-taineje sistemoje:" | |
echo "A" | |
else | |
if [ $desimtainis = "11" ] | |
then | |
echo "Skaicius 16-taineje sistemoje:" | |
echo "B" | |
else | |
if [ $desimtainis = "12" ] | |
then | |
echo "Skaicius 16-taineje sistemoje:" | |
echo "C" | |
else | |
if [ $desimtainis = "13" ] | |
then | |
echo "Skaicius 16-taineje sistemoje:" | |
echo "D" | |
else | |
if [ $desimtainis = "14" ] | |
then | |
echo "Skaicius 16-taineje sistemoje:" | |
echo "E" | |
else | |
if [ $desimtainis = "15" ] | |
then | |
echo "Skaicius 16-taineje sistemoje:" | |
echo "F" | |
else | |
if [ $desimtainis = "0" ] || | |
[ $desimtainis = "1" ] || | |
[ $desimtainis = "2" ] || | |
[ $desimtainis = "3" ] || | |
[ $desimtainis = "4" ] || | |
[ $desimtainis = "5" ] || | |
[ $desimtainis = "6" ] || | |
[ $desimtainis = "7" ] || | |
[ $desimtainis = "8" ] || | |
[ $desimtainis = "9" ] | |
then | |
echo "Skaicius 16-taineje sistemoje:" | |
echo "$desimtainis" | |
else | |
if [ $desimtainis == "A" ] || | |
[ $desimtainis == "B" ] || | |
[ $desimtainis == "C" ] || | |
[ $desimtainis == "D" ] || | |
[ $desimtainis == "E" ] || | |
[ $desimtainis == "F" ] || | |
[ $desimtainis == "G" ] || | |
[ $desimtainis == "H" ] || | |
[ $desimtainis == "I" ] || | |
[ $desimtainis == "J" ] || | |
[ $desimtainis == "K" ] || | |
[ $desimtainis == "L" ] || | |
[ $desimtainis == "M" ] || | |
[ $desimtainis == "N" ] || | |
[ $desimtainis == "O" ] || | |
[ $desimtainis == "P" ] || | |
[ $desimtainis == "Q" ] || | |
[ $desimtainis == "R" ] || | |
[ $desimtainis == "S" ] || | |
[ $desimtainis == "T" ] || | |
[ $desimtainis == "U" ] || | |
[ $desimtainis == "V" ] || | |
[ $desimtainis == "W" ] || | |
[ $desimtainis == "X" ] || | |
[ $desimtainis == "Y" ] || | |
[ $desimtainis == "Z" ] || | |
[ $desimtainis == "a" ] || | |
[ $desimtainis == "b" ] || | |
[ $desimtainis == "c" ] || | |
[ $desimtainis == "d" ] || | |
[ $desimtainis == "e" ] || | |
[ $desimtainis == "f" ] || | |
[ $desimtainis == "g" ] || | |
[ $desimtainis == "h" ] || | |
[ $desimtainis == "i" ] || | |
[ $desimtainis == "j" ] || | |
[ $desimtainis == "k" ] || | |
[ $desimtainis == "l" ] || | |
[ $desimtainis == "m" ] || | |
[ $desimtainis == "n" ] || | |
[ $desimtainis == "o" ] || | |
[ $desimtainis == "p" ] || | |
[ $desimtainis == "q" ] || | |
[ $desimtainis == "r" ] || | |
[ $desimtainis == "s" ] || | |
[ $desimtainis == "t" ] || | |
[ $desimtainis == "u" ] || | |
[ $desimtainis == "v" ] || | |
[ $desimtainis == "w" ] || | |
[ $desimtainis == "x" ] || | |
[ $desimtainis == "y" ] || | |
[ $desimtainis == "z" ] | |
then | |
echo "Skaicius nera desimtainis!" | |
fi | |
fi | |
fi | |
fi | |
fi | |
fi | |
fi | |
fi | |
fi | |
fi | |
else | |
if [ $number = "3" ] | |
then | |
exit 0 | |
else | |
if [ $number != "1" -a $number != "2" -a $number != "3" ] | |
then | |
echo "Pasirinkote netinkama komanda" | |
fi | |
fi | |
fi | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
būtų idealu jei pasiektume 100% test coverage SHIP IT