Задача А.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream fin;
ofstream fout;
fin.open("polybius.dat",ios::in);
fout.open("polybius.sol",ios::out);
int n,l,i,j,c;
char a[6][6]
{ {'0','0','0','0','0','0'},
{'0','A','B','C','D','E'},
{'0','F','G','H','I','K'},
{'0','L','M','N','O','P'},
{'0','Q','R','S','T','U'},
{'0','V','W','X','Y','Z'}
};
fin>>n;
for(i=1;i<=n;i++)
{
fin>>l;
for(j=1;j<=l;j++)
{
fin>>c;
fout<<a[c%10][c/10];
}
fout<<endl;
}
}
Задача В.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
// ifstream fin;
//ofstream fout;
//fin.open("birthday.dat",ios::in);
//fout.open("birthday.sol",ios::out);
int n,s,k,i,t=0,u,z;
cin>>n>>s>>k;
u=k;
if(u%2==0)z=u/2; else z=u/2+1;
t+=z;
i=1;
while(t<n)
{
i++;
u+=s;
if(u%2==0)z=u/2; else z=u/2+1;
t+=z;
}
cout<<i;
}
Задача С.
#include <iostream>
#include <stdio.h>
using namespace std;
long long number(long long a, long long b, long long c, long long d)
{
long long num=0;
num=a*1000000000;
num+=b*1000000;
num+=c*1000;
num+=d;
return num;
}
int main()
{
long long a[1001][15],i,j,n,max,ip1,nmax,t,k;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
cin>>n;
for(i=1;i<=n;i++)
{
for(j=1;j<=8;j++)
{
cin>>a[i][j];
if (j==5) a[i][9]=number(a[i][1],a[i][2],a[i][3],a[i][4]);
if (j==8) a[i][10]=number(a[i][5],a[i][6],a[i][7],a[i][8]);
}
a[i][11]=1;a[i][12]=1;
}
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
if(a[i][9]==a[j][9] && a[j][11]>0){a[i][11]++;a[j][11]=0;}
max=-1; nmax=1;
for(i=1;i<=n;i++)
if(max<a[i][11]) {max=a[i][11];ip1=a[i][9];nmax=i;}
cout<<a[nmax][1]<<'.'<<a[nmax][2]<<'.'<<a[nmax][3]<<'.'<<a[nmax][4]<<endl<<"---------------"<<endl;
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
if(a[j][9]==ip1 && a[i][9]==ip1 && a[i][10]==a[j][10] && a[j][12]>0){a[i][12]++;a[j][12]=0;}
for(i=1;i<=n;i++)
for(j=1;j<=n-i;j++)
if(a[j][12]<a[j+1][12] || (a[j][12]==a[j+1][12] && a[j][10]>a[j+1][10])){for(k=1;k<=12;k++){t=a[j][k]; a[j][k]=a[j+1][k]; a[j+1][k]=t;}}
for(i=1;i<=n;i++)
if(ip1==a[i][9] && a[i][12]>0) cout<<a[i][12]<<" - "<<a[i][5]<<'.'<<a[i][6]<<'.'<<a[i][7]<<'.'<<a[i][8]<<endl;
}
Задача D.
#include <iostream>
#include <fstream>
using namespace std;
int n,p,a[11][11]={0},ship[46][6],u=0;
void shipmap(int x1,int y1, int x2, int y2)
{
if(x1==x2) for(int i=y1;i<=y2;i++)
a[x1][i]=-1;
if(y1==y2) for(int i=x1;i<=x2;i++)
a[i][y1]=-1;
}
void check(int r,int c)
{
int i;
for(i=1;i<=1.0*(p+1)/2*p;i++)
{
if(r==ship[i][1] && r==ship[i][3] && c>=ship[i][2] && c<=ship[i][4])
if (ship[i][0]==0){ship[i][0]=1; u++; ship[i][5]=r*10+c;}
if(c==ship[i][2] && c==ship[i][4] && r>=ship[i][1] && r<=ship[i][3])
if (ship[i][0]==0){ship[i][0]=1; u++; ship[i][5]=r*10+c;}
}
}
int main()
{
ifstream fin;
ofstream fout;
fin.open("battleship.dat",ios::in);
fout.open("battleship.sol",ios::out);
int i,j,k,x1,x2,y1,y2;
fin>>n>>p;
k=1.0*(p+1)/2*p;
for(i=1;i<=k;i++)
{
fin>>x1>>y1>>x2>>y2;
shipmap(x1,y1,x2,y2);
ship[i][1]=x1;ship[i][2]=y1;ship[i][3]=x2;ship[i][4]=y2;
}
int r=1,c=1,t=0;
k=n-1;
while(u<1.0*(p+1)/2*p)
{
if(k%n!=0)r=k/n+1;else r=k/n;
if(k%n!=0)c=k%n;else c=n;
if(r>n){r=1;k=c;}
t++;
if(a[r][c]==-1)
check(r,c);
a[r][c]=t;
k+=n-1;
}
fout<<t;
}
Задача Е.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
//ifstream fin;
//ofstream fout;
//fin.open("input.dat",ios::in);
//fout.open("output.sol",ios::out);
int n,m,a[51][51]={0},k=0,i,j,x1,y1,x2,y2,t;
cin>>n>>m>>x1>>y1>>x2>>y2;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{
cin>>a[i][j];
if(a[i][j]==0)a[i][j]=-2;
}
a[x1][y1]=0;
if(x1==x2&&y1==y2)cout<<0; else
{
k=0;
t=1;
while(t==1)
{
t=0;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
if(a[i][j]==k)
{
if(a[i-1][j]==-2&&a[i-1][j]!=-1){a[i-1][j]=k+1; t=1;}
if(a[i+1][j]==-2&&a[i+1][j]!=-1){a[i+1][j]=k+1; t=1;}
if(a[i][j-1]==-2&&a[i][j-1]!=-1){a[i][j-1]=k+1; t=1;}
if(a[i][j+1]==-2&&a[i][j+1]!=-1){a[i][j+1]=k+1; t=1;}
}
k++;
}
if (a[x2][y2]!=-2)cout<<a[x2][y2]; else cout<<"No";
}
}