Pagini recente » Cod sursa (job #556781) | Cod sursa (job #870311) | Cod sursa (job #3000923) | Cod sursa (job #2911834) | Cod sursa (job #1398780)
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
ifstream fin("mxl.in");
ofstream fout("mxl.out");
int a[41][41],n,i,j,k,x,y,q,ii;
struct punct
{
int r,x,y;
char c[256];
};
punct b[1601];
bool ok,ok1;
int main()
{
fin>>n>>k;
q=k;
for(i=1;i<=k;i++)
{
fin>>b[i].x>>b[i].y;
fin>>b[i].c;
if(b[i].c[0]!='=')
{
for(j=0;j<strlen(b[i].c);j++)
{
b[i].r=b[i].r*10+(b[i].c[j]-'0');
}
q--;
}
else
{
ok=true;
x=0;
ok1=false;
for(j=1;j<strlen(b[i].c)&&ok;j++)
{
if(b[i].c[j]=='+')
{
b[i].r=b[i].r+x;
x=0;
ok1=true;
}
else if(b[i].c[j]==':') ok=false;
else
{
x=x*10+(b[i].c[j]-'0');
}
}
if(x!=0) b[i].r+=x;
if(ok==false) b[i].r=0;
if(ok1==false&&ok) b[i].r=x;
if(ok) q--;
}
}
i=1;
while(q!=0)
{
if(b[i].r==0)
{
x=0;
y=0;
for(j=1;j<strlen(b[i].c);j++)
{
if(b[i].c[j]=='+')
{
b[i].r=b[i].r+x;
x=0;
}
else if(b[i].c[j]==':')
{
j++;
ok=false;
while(b[i].c[j]>='0'&&b[i].c[j]<='9')
{
y=y*10+(b[i].c[j]-'0');
j++;
}
for(ii=1;ii<=k&&ok==false;ii++)
{
if(x==b[ii].x&&y==b[ii].y&&b[ii].r!=0)
{
b[i].r=b[i].r+b[ii].r;
ok=true;
}
}
if(ok==false)
{
b[i].r=0;
j=strlen(b[i].c);
}
x=0;
y=0;
}
else
{
x=x*10+(b[i].c[j]-'0');
}
}
if(x!=0&&b[i].r!=0) b[i].r=b[i].r+x;
if(b[i].r!=0) q--;
}
i++;
if(i>k) i=1;
}
for(i=1;i<=k;i++)
{
a[b[i].x][b[i].y]=b[i].r;
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
fout<<a[i][j]<<" ";
fout<<"\n";
}
return 0;
}