Problems

# Roman numerals

published at 6/7/15, 4:21:47 pm

Не усі числа менші за 2000, а лише вхідні дані.

published at 4/8/16, 1:01:45 pm

Компилятор C++ Мы должны вернуть строку, но пишет, что main должен быть int. Как так?

published at 5/27/16, 10:39:50 pm

А как правильно определить ету переменую в Пайтон

published at 3/16/18, 3:56:30 pm

Складна задача, довго прийшлось "шурупати" мозгами

published at 11/5/18, 11:52:43 pm

Авторе протестуйте ось цей код і скажіть Чи по логічному він працює. s = str(input()) s1 = str() s2 = str() y = 0 p = 0 for i in range(0, len(s)): if s[i] != "+": s1 += s[i] else: y = i break for i in range(y + 1, len(s)): s2 += s[i] print(s1, s2) k = 0 for i in range(0, len(s1)): if s1[i] == "I" and i > 0 and s1[i - 1] == "V" or s1[i] == "I" and i > 0 and s1[i - 1] == "X" or s1[i] == "I" and i > 0 and s1[i - 1] == "L" or s1[i] == "I" and i > 0 and s1[i - 1] == "C" or s1[i] == "I" and i > 0 and s1[ i - 1] == "D" or s1[i] == "I" and i > 0 and s1[i - 1] == "M": p -= 1 k = 1 else: if s1[i] == "I": p += 1 elif s1[i] == "V": p += 5 elif s1[i] == "X": p += 10 elif s1[i] == "L": p += 50 elif s1[i] == "C": p += 100 elif s1[i] == "D": p += 500 else: p += 1000 if k == 1: i += 1 k == 0 for i in range(0, len(s2)): if s2[i] == "I" and i > 0 and s2[i - 1] == "V" or s2[i] == "I" and i > 0 and s2[i - 1] == "X" or s2[i] == "I" and i > 0 and s2[i - 1] == "L" or s2[i] == "I" and i > 0 and s2[i - 1] == "C" or s2[i] == "I" and i > 0 and s2[ i - 1] == "D" or s2[i] == "I" and i > 0 and s2[i - 1] == "M": p -= 1 k += 1 else: if s2[i] == "I": p += 1 elif s2[i] == "V": p += 5 elif s2[i] == "X": p += 10 elif s2[i] == "L": p += 50 elif s2[i] == "C": p += 100 elif s2[i] == "D": p += 500 else: p += 1000 if k == 1: i += 1 str = str() while p >= 1000: p -= 1000 str += "M" if p == 999: p -= 999 str += "MI" while p >= 500: p -= 500 str += "D" if p == 499: p -= 499 str += "DI" while p >= 100: p -= 100 str += "C" if p == 99: p -= 99 str += "CI" while p >= 50: p -= 50 str += "L" if p == 49: p -= 49 str += "LI" while p >= 10: p -= 10 str += "X" if p == 9: p -= 9 str += "XI" while p >= 5: p -= 5 str += "V" if p == 4: p -= 4 str += "VI" while p >= 1: p -= 1 str += "I" print(str)

published at 3/2/19, 12:11:08 pm

не могу никак реыть ету задачу киньте кто решение

published at 11/3/19, 10:20:54 pm

git hut can you put this code in github?

published at 11/23/19, 1:25:02 pm

"""RUM REQEMLERI"""

def nums(x): case={ "X":10, "L":50, "D":500, "C":100, "V":5, "I":1, }

return case.get(x)


def netice(y): #netice ingilis dinlinde nedi ona bax! = result

case={
0:None,
1:"I",
4:"IV",
5:"V",
9:"IX",
10:"X",
50:"L",
100:"C",
500:"D",
}
ll = case.keys()
ld = list(ll)
aa = 7
ccc = y
ddd = []
ok = 1
aze =1
for i in range(len(case)):
while y>=0 and aa>=0:
if ld[aa]<=y:
if(aa!=8):
if ld[aa+1] <= y:
aze+=1
print(aze,'\taze')
y -= ld[aa+1]
print(y,'\tssaaaaaascs')
ddd += [case.get(ld[aa+1])]
aa+=1
else:
print("----------------------------")
y -= ld[aa]
print(y,'\tssscs')
ddd += [case.get(ld[aa])]
print(ddd,'\tddd')
ok+=1
print(ok,'ok')

aa -=1
print(aa,'\taa')
return ddd

print("\n")

return case.get(y)


def tapici(ll): cc = [] dd = 0 for i in range(len(ll)): if ll[i] == "None": cc += [] else: cc += [ll[i]] for i in range(len(cc)): dd +=int(cc[i])

return dd


num = input()

other =[] numlis=list(num)

for i in range(len(numlis)): other.append(str(nums(numlis[i])))

for i in range(len(other)): if i<=len(other)-1: if other[i]=="1" and other[i+1]=="5": other[i] = str(int(other[i+1])-int(other[i])) del other[i+1] if other[i]=="1" and other[i+1]=="10": other[i]= str(int(other[i+1])-int(other[i])) del other[i+1]

print (other)

ll =[] ll +=[str(tapici(other))] ff = ll[0] print(ff,'fffffffffff')

bb = [] bb += netice(int(ff)) sss='' if len(bb)>1: for i in range(len(bb)): sss += bb[i] print("CAVAB:\t",sss,end =None) else: print("CAVAB\t",bb[0],end=None)

published at 6/27/20, 2:28:11 pm

С javascript работать невозможно. Попытался понять, что мне дают на вход: Оказалось это какой-то двумерный массив, размер которого меняется время от времени (я опытным путём определил, что там существуют элементы с индексами arr[6][3] и подобные)... (я это вычислял многоразовыми отправками, способом просмотра есть ли ошибка выполнения или нет). Шутники какие-то прям. Пытаться решить задачу для другого устройства если не знаешь его интерфейса это, конечно, очень весело, но не для меня.

published at 8/24/20, 12:02:01 pm

Получилось решить эту задачу, не используя другие системы счисления. Подсказка: можно завести два списка для римских чисел, которые складываются и которые отнимаются.

published at 1/26/21, 12:17:01 pm

program lol;

uses graph,crt; var dv,mv:integer; i,t,mx,my:longint; x,y,speed:real; a,b:integer;

procedure myPut(x,y:real); begin putpixel(round(getmaxX div 2 + x*mx),round(getmaxY div 2-y*my),10); end;

begin dv:=detect; initgraph(dv,mv,''); cleardevice; a:=getMaxX; b:=getmaxy; mx:=60; my:=50; speed:=0.001; ///krestik setlinestyle(3,0,1); setcolor(10); line(a div 2,0,a div 2,b); line(0,b div 2,a,b div 2);

// 1 x:=-2.65; while x<2.65 do begin y:=(x*x)/1.5 +5.03; myPut(x,y); x:=x+speed; end;

// 2 x:=-2.6; while x<2.6 do begin y:=-(x*x)/sqr(1.8)+5; myPut(x,y); x:=x+speed; end;

// 3 x:=-2; while x<0 do begin y:=-sqr(x+1.5)+4; myPut(x,y); x:=x+speed; end;

// 4 x:=0; while x<2 do begin y:=-sqr(x-1.5)+4; myPut(x,y); x:=x+speed; end;

// 5 x:=-2.65; while x<0 do begin y:=-sqr(x+1.5)+11; myPut(x,y); x:=x+speed; end;

// 6 x:=0; while x<2.65 do begin y:=-sqr(x-1.5)+11; myPut(x,y); x:=x+speed; end;

// 7 x:=-0.75; while x<0.75 do begin y:=-x*x+11; myPut(x,y); x:=x+speed; end;

// 8 x:=-2; while x<0 do begin y:=-sqr(x+1.5)+8; myPut(x,y); x:=x+speed; end;

// 9 x:=0; while x<2 do begin y:=-sqr(x-1.5)+8; myPut(x,y); x:=x+speed; end;

repeat until keypressed; closegraph; end.

published at 3/13/21, 8:06:31 pm

Abbas bunu tapsan sənə ne deyim da bekarsa.

published at 3/16/21, 8:35:54 pm

# include<bits/stdc++.h>

using namespace std; int main() { string s; long long a=0,b,c,d,e; getline(cin,s); for(int i=0;i<s.size();i++){ if(s[i]=='+'){ b=a; a=0; i++; } if(s[i]=='I'&&s[i+1]!='V'&&s[i+1]!='X'){

a++;


} else if(s[i]=='I'&&s[i+1]=='V'){ a+=4; i++; } else if(s[i]=='I'&&s[i+1]=='X'){ a+=9; i++; } else if(s[i]=='V'){ a+=5; } else if(s[i]=='X'&&s[i+1]!='L'&&s[i+1]!='C'){ a+=10; } else if(s[i]=='X'&&s[i+1]=='L'){ a+=40; i++; } else if(s[i]=='X'&&s[i+1]=='C'){ a+=90; i++; } else if(s[i]=='L'){ a+=50; } else if(s[i]=='C'&&s[i+1]!='D'&&s[i+1]!='M'){ a+=100; } else if(s[i]=='C'&&s[i+1]=='D'){ a+=400; i++; } else if(s[i]=='C'&&s[i+1]=='M'){ a+=900; i++; } else if(s[i]=='D'){ a+=500; } else if(s[i]=='M'){ a+=1000; }

} a=a+b; while(a>0){ if(a>=1000){ cout<<"M"; a-=1000; } else if(a>=900){ cout<<"CM"; a-=900; } else if(a>=500){ cout<<"D"; a-=500; } else if(a>=400){ cout<<"CD"; a-=400; } else if(a>=100){ cout<<"C"; a-=100; } else if(a>=90){ cout<<"XC"; a-=90; } else if(a>=50){ cout<<"L"; a-=50; } else if(a>=40){ cout<<"XL"; a-=40; } else if(a>=10){ cout<<"X"; a-=10; } else if(a>=9){ cout<<"IX"; a-=9; } else if(a>=5){ cout<<"V"; a-=5; } else if(a>=4){ cout<<"IV"; a-=4; } else if(a>=1){ cout<<"I"; a-=1; } }

}

published at 12/8/21, 3:52:37 pm

TYPE DigStr = string[2]; CONST Digs:Array[1..13] of DigStr = ('I','IV','V','IX','X','XL','L','XC','C','CD','D','CM','M'); Vals:Array[1..13] of longint = (1,4,5,9,10,40,50,90,100,400,500,900,1000); VAR sum:longint; S, temp, st1, st2:string; c:char; FUNCTION Dig(C:char):longint; begin case C of 'I':Dig:=1; 'V':Dig:=5; 'X':Dig:=10; 'L':Dig:=50; 'C':Dig:=100; 'D':Dig:=500; 'M':Dig:=1000; end; end; FUNCTION RomanToArab(var S:string):longint; var Sum,i,Len:longint; begin Sum:=0; i:=1; Len:=length(S); while i<Len do begin if Dig(S[i])<Dig(S[i+1]) then begin Sum:=Sum+Dig(S[i+1])-Dig(S[i]); i:=i+1; end else Sum:=Sum+Dig(S[i]); i:=i+1; end; if i=Len then Sum:=Sum+Dig(S[Len]); RomanToArab:=Sum; end; FUNCTION ArabToRoman(Num:longint):string; var S:String; K,i:longint; begin i:=13; S:=''; K:=Num; while i<>0 do if K>=Vals[i] then begin K:=K-Vals[i]; S:=S+Digs[i]; end else dec(i); ArabToRoman:=S; end; BEGIN st1:=''; read (c); while c<>'+' do begin st1:=st1+c; read (c); end; st2:=''; while not(eoln) do begin read (c); st2:=st2+c; end; sum:=RomanToArab(st1)+RomanToArab(st2); writeln(ArabToRoman(sum)); END.

published at 4/9/22, 11:09:05 am

в питоне есть фреймворк римских чисел.Итого можно решить это за 2 строки с фреймворком Решение: from roman import * print(romaneval(romaninput()))

published at 9/24/22, 4:50:29 pm

using System;

class Program { static void Main(string[] args) { string console = Console.ReadLine(); string[] rum = console.Split("+"); string rumDecoded = ""; int n = 0; for(int i = 0; i < rum.Length; i++) { char[] rumLetter = rum[i].ToCharArray(); for(int p = 0; p < rumLetter.Length; p++) { int d = GetNumber(rumLetter[p]); if ((rumLetter.Length - p) > 1) { if (d < GetNumber(rumLetter[p + 1])) { n -= d; } else { n += d; } } else { n += d; } } } Console.WriteLine(GetRoman(n)); }

static int GetNumber(char letter)
{
int n = 0;
if(letter == 'I')
{
n = 1;
}
if(letter == 'V')
{
n = 5;
}
if (letter == 'X')
{
n = 10;
}
if (letter == 'L')
{
n = 50;
}
if (letter == 'C')
{
n = 100;
}
if (letter == 'D')
{
n = 500;
}
if (letter == 'M')
{
n = 1000;
}
return n;
}
public static string GetRoman(int number)
{
if ((number < 0) || (number > 3999)) throw new ArgumentOutOfRangeException("insert value betwheen 1 and 3999");
if (number < 1) return string.Empty;
if (number >= 1000) return "M" + GetRoman(number - 1000);
if (number >= 900) return "CM" + GetRoman(number - 900);
if (number >= 500) return "D" + GetRoman(number - 500);
if (number >= 400) return "CD" + GetRoman(number - 400);
if (number >= 100) return "C" + GetRoman(number - 100);
if (number >= 90) return "XC" + GetRoman(number - 90);
if (number >= 50) return "L" + GetRoman(number - 50);
if (number >= 40) return "XL" + GetRoman(number - 40);
if (number >= 10) return "X" + GetRoman(number - 10);
if (number >= 9) return "IX" + GetRoman(number - 9);
if (number >= 5) return "V" + GetRoman(number - 5);
if (number >= 4) return "IV" + GetRoman(number - 4);
if (number >= 1) return "I" + GetRoman(number - 1);
}


}

published at 2/13/23, 6:35:04 pm

class Solution: def intToRoman(self, num: int) -> str: s = "" d : dict = { 9:'IX', 4:'IV', 40:'XL', 90:'XC', 400:'CD', 900:'CM' } while num > 0: if num // 1000 != 0: s += 'M' * (num // 1000) num = num % 1000

      if num // 100 != 0:
x = 100 * (num // 100)
if 100 <= x <= 300:
s += 'C' * (x // 100)
elif x == 400:
s += d[400]
elif x == 900:
s += d[900]
else:
s += 'D' + 'C' * (x // 100 - 5)
num = num % 100

if num // 10 != 0:
x = 10 * (num // 10)

if 10 <= x <= 30:
s += 'X' * (x // 10)
elif x == 40:
s += d[40]
elif x == 90:
s += d[90]
else:
s += 'L' + 'X' * (x // 10 - 5)
num = num % 10
if 1 <= num <= 3:
s += 'I' * num
elif num == 4:
s += d[4]
elif num == 9:
s += d[9]
elif num != 0:
s += 'V' + 'I' * (num - 5)
break
return s
def roman_to_number(self,s: str) -> int:
roman:dict = {
"I":1,
"V":5,
"X":10,
"L":50,
"C":100,
"D":500,
"M":1000


} ans = 0 for i in range(len(s)): if i + 1 < len(s) and roman[s[i]] < roman[s[i + 1]]: ans -= roman[s[i]] else: ans += roman[s[i]] return ans

num: str = input()

s = num.split('+')

sol = Solution()

integer = sol.romantonumber(s[0]) + sol.romantonumber(s[1])

print(sol.intToRoman(integer))