HDU3344(小广搜+小暴力
Kakuro Extension Extension
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 507 Accepted Submission(s): 248
Then T case follow:
Each test case starts with a line contains two numbers N,M (2<=N,M<=100)and then N lines follow, each line contains M columns, either ‘_’ or 1~9. You can assume that the first column of the first line is ’_’.
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
char a[105][105];
void pd(int x,int y,int m,int n)
{
if(a[x][y]>='1'&&a[x][y]<='9')
{
printf(".......");
return ;
}
int sum1=0,sum2=0;
int flag1=0;
int flag2=0;
if(x==m)
flag1=1;
if(y==n)
flag2=1;
for(int i=x+1; i<=m; i++)
{
if(a[x+1][y]=='_')
flag1=1;
if(a[i][y]=='_')
break;
sum1=sum1+(a[i][y]-'0');
}
for(int j=y+1; j<=n; j++)
{
if(a[x][y+1]=='_')
flag2=1;
if(a[x][j]=='_')
break;
sum2=sum2+(a[x][j]-'0');
}
if(flag1==1&&flag2==1)
{
printf("XXXXXXX");
}
else if(flag1==1&&flag2==0)
{
printf("XXX");
printf("\\");
printf("%03d",sum2);
}
else if(flag1==0&&flag2==1)
{
printf("%03d",sum1);
printf("\\");
printf("XXX");
}
else if(flag1==0&&flag2==0)
{
printf("%03d\\%03d",sum1,sum2);
}
}
int main()
{
int m,n;
int t;
scanf("%d",&t);
while(t--)
{
memset(a,0,sizeof(a));
scanf("%d%d",&m,&n);
getchar();
for(int i=1; i<=m; i++)
{
for(int j=1; j<=n; j++)
{
//scanf("%c",&a[i][j]);
cin >> a[i][j];
}
}
char ch=' ';
for(int i=1; i<=m; i++)
{
for(int j=1; j<=n; j++)
{
/*if(a[1][1]!='_')
a[1][1]='_';*/
pd(i,j,m,n);
if(j!=n)
printf("%c",ch);
}
printf("\n");
}
printf("\n");
}
return 0;
}