//\\__ hr1212 __//\\
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 1000000007
int n,m,b[1010][1010];
string a[1010][1010];
int solve(int i,int j){
if(b[i][j]!=1e9)
return b[i][j];
int z=0,k,l,x,y;
string s,p;
f(k,1,a[i][j].size()){
if(a[i][j][k]>='A' && a[i][j][k]<='Z')
s+=a[i][j][k];
if(a[i][j][k]>='0' && a[i][j][k]<='9')
p+=a[i][j][k];
if(a[i][j][k]=='+' || k==a[i][j].size()-1){
x=0;y=0;
f(l,0,s.size())
y=y*26+(s[l]-'A'+1);
f(l,0,p.size())
x=x*10+(p[l]-'0');
x--;y--;
z+=solve(x,y);
s.clear();p.clear();
}
}
return b[i][j]=z;
}
int main(){
int r,k,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
ll ans=0;string p;
si(t);
while(t--){
sii(m,n);
f(i,0,n){
f(j,0,m){
b[i][j]=1e9;
cin>>a[i][j];
if(a[i][j][0]!='=')
b[i][j] = atoi(a[i][j].c_str());
}
}
f(i,0,n){
f(j,0,m){
if(b[i][j]==1e9)
solve(i,j);
if(j==m-1)
printf("%d",b[i][j]);
else
printf("%d ",b[i][j]);
}
nl;
}
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 1000000007
int n,m,b[1010][1010];
string a[1010][1010];
int solve(int i,int j){
if(b[i][j]!=1e9)
return b[i][j];
int z=0,k,l,x,y;
string s,p;
f(k,1,a[i][j].size()){
if(a[i][j][k]>='A' && a[i][j][k]<='Z')
s+=a[i][j][k];
if(a[i][j][k]>='0' && a[i][j][k]<='9')
p+=a[i][j][k];
if(a[i][j][k]=='+' || k==a[i][j].size()-1){
x=0;y=0;
f(l,0,s.size())
y=y*26+(s[l]-'A'+1);
f(l,0,p.size())
x=x*10+(p[l]-'0');
x--;y--;
z+=solve(x,y);
s.clear();p.clear();
}
}
return b[i][j]=z;
}
int main(){
int r,k,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
ll ans=0;string p;
si(t);
while(t--){
sii(m,n);
f(i,0,n){
f(j,0,m){
b[i][j]=1e9;
cin>>a[i][j];
if(a[i][j][0]!='=')
b[i][j] = atoi(a[i][j].c_str());
}
}
f(i,0,n){
f(j,0,m){
if(b[i][j]==1e9)
solve(i,j);
if(j==m-1)
printf("%d",b[i][j]);
else
printf("%d ",b[i][j]);
}
nl;
}
}
return 0;
}
No comments:
Post a Comment