Задача А. Кохан Андрій
table=[[0 for i in range(5)]for j in range(5)]
co=65
for i in range(5):
for j in range(5):
table[i][j]=chr(co)
co+=1
if chr(co)=="J":
co+=1
txt=open('polybius.dat', 'r')
out=open('polybius.sol', 'w')
n=int(txt.readline())
for i in range(n):
code=list(map(str, txt.readline().split()))
length=code.pop(0)
for i in range(int(length)):
out.write (table[int(code[i][1])-1][int(code[i][0])-1])
out.write('\n')
txt.close()
out.close()
Задача В. Буйніцька Ольга
program glllk;
var d,i,j,n,r,s,k:integer;
BEGIN
readln(n,s,k);
r:=k-(k div 2);i:=1;d:=k;
while r<n do
begin
i:=i+1;
d:=d+s;
r:=r+(d-(d div 2));
end;
writeln(i);
END.
Задача С. Скрипник Денис
#include <bits/stdc++.h>
using namespace std;
bool comp_str(string s1, string s2){
int a[4];
int b[4];
int i = 0;
string token;
istringstream iss(s1);
while( getline(iss, token, '.') ){
a[i++] = stoi(token);
}
i = 0;
iss.clear();
iss.str(s2);
while( getline(iss, token, '.') ){
b[i++] = stoi(token);
}
for( i = 0;i<4;++i ){
if ( a[i] < b[i] )
return true;
}
return false;
}
bool comp( const pair<string, int>& i, const pair<string, int>& j ) {
if( i.second < j.second ) return false;
if( j.second < i.second ) return true;
return comp_str(i.first, j.first);
}
int main()
{
ios_base::sync_with_stdio(false);
map<string, pair<int, map<string, int> > > servers;
vector< pair<string, int> > res;
int n, a, b, c, d, i;
string str, str2;
cin >> n;
for ( i = 0;i<n;++i ){
cin >> a >> b >> c >> d;
str = to_string(a) + "." + to_string(b) + "." +
to_string(c) + "." + to_string(d);
cin >> a >> b >> c >> d;
str2 = to_string(a) + "." + to_string(b) + "." +
to_string(c) + "." + to_string(d);
servers[str].first++;
servers[str].second[str2]++;
}
str = "";
int mx = 0;
for ( auto it = servers.cbegin();it != servers.cend(); ++it ){
if ( (it->second).first > mx ){
mx = (it->second).first;
str = it->first;
}
}
auto it = (servers.at(str).second).begin();
auto en = (servers.at(str).second).end();
for ( ;it != en; ++it ){
res.push_back(make_pair(it->first, it->second));
}
sort(res.begin(), res.end(), comp);
//Result
cout << str << '\n';
for(i = 0;i<15;++i)
cout << "-";
cout << '\n';
for_each(res.begin(), res.end(), [](pair<string, int> p){
cout << p.second << " - " << p.first << '\n';
});
}
Задача D. Романець Андрій
########### START INPUT ###########
f = open('battleship.dat', 'r')
mas = list(map(int, f.readline().split()));
n, p = mas
for i in f.readlines():
mas.append(list(map(int, i.split())))
del(mas[0])
del(mas[0])
i = 0
for l in mas:
#print(l)
mas[i] = [l[i:i + 2] for i in range(0, len(l), 2)]
i += 1
f.close()
########### END INPUT ###########
lt = []
for i in range(n):
lt.append(list([0] * n))
v = 1
masShip = []
for g in mas:
x1 = g[0][0]-1
y1 = g[0][1]-1
x2 = g[1][0]-1
y2 = g[1][1]-1
if (x1 == x2):
y = y1
while(y <= y2):
lt[x1][y] = v
y += 1
if (y1 == y2):
x = x1
while(x <= x2):
lt[x][y1] = v
x += 1
masShip.append(v)
v += 1;
ltn = []
for i in lt:
ltn += i
b = True
cur = n - 1;
amount = 0
while (b):
if (cur >= n*n):
cur -= n*n
if (ltn[cur-1] != 0):
masShip[ltn[cur-1]-1] = -1;
cur += n-1
amount += 1
a = set(masShip)
if (a == {-1}):
break
if (amount > 100):
amount
break
f = open('battleship.sol', 'w')
print(amount, file = f)
f.close()
Задача E. Акуліч Даниїл
#include <iostream>
#include <queue>
#include <stdio.h>
using namespace std;
int c,x,y,n,m,sx,sy,ex,ey,i,j,c2,k;
int main()
{
//freopen("input.dat","r",stdin);
//freopen("output.dat","w",stdout);
c=0;x=0;y=0;
cin>>n>>m;
int lab[m][n];
cin>>sy>>sx>>ex>>ey;
sx=sx-1;
sy=sy-1;
ex=ex-1;
ey=ey-1;
for(k=0;k<n;k++){for(j=0;j<m;j++){cin>>lab[j][k];}}
lab[sx][sy]=1;
c=1;
c2=0;
while(c2==0)
{
c2=1;
x=0;
y=0;
for(i=0;i<m*n;i++)
{
if(lab[x][y]==c)
{
if(lab[x-1][y]==0&&x!=0){lab[x-1][y]=c+1;c2=0;}
if(lab[x+1][y]==0&&x!=m){lab[x+1][y]=c+1;c2=0;}
if(lab[x][y-1]==0&&y!=0){lab[x][y-1]=c+1;c2=0;}
if(lab[x][y+1]==0&&y!=n-1){lab[x][y+1]=c+1;c2=0;}
}
x++;
if(x==m){x=0;y++;}
}
c++;
}
if(lab[ey][ex]==-1||lab[ey][ex]==0){cout<<"No"<<endl;}
else {cout<<lab[ey][ex]-1<<endl;}
return 0;
}