hdu 3344 Kakuro Extension Extension

邢杰
2023-12-01

Kakuro Extension Extension

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 468    Accepted Submission(s): 240


Problem Description
You know ,I'm a lazy guy and write problem description is a very very boring thing.So , I would not repeat the rule of Kakuro again , Please look at  this.But things are different again,contray to the problem above,this time you should work out the input file according to the output file.
 

Input
The first line of the inputs is T, which stands for the number of test cases you need to solve.
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 ’_’.
 

Output
Output N lines, each line contains M parts, each part contains 7 letters. The m parts are seperated by spaces.Output a blank line after each case.
 

Sample Input
2 6 6 _ _ _ _ _ _ _ _ 5 8 9 _ _ 7 6 9 8 4 _ 6 8 _ 7 6 _ 9 2 7 4 _ _ _ 7 9 _ _ 5 8 _ _ _ _ _ _ _ _ _ 1 9 9 1 1 8 6 _ _ 1 7 7 9 1 9 _ 1 3 9 9 9 3 9 _ 6 7 2 4 9 2 _
 

Sample Output
XXXXXXX XXXXXXX 028\XXX 017\XXX 028\XXX XXXXXXX XXXXXXX 022\022 ....... ....... ....... 010\XXX XXX\034 ....... ....... ....... ....... ....... XXX\014 ....... ....... 016\013 ....... ....... XXX\022 ....... ....... ....... ....... XXXXXXX XXXXXXX XXX\016 ....... ....... XXXXXXX XXXXXXX XXXXXXX 001\XXX 020\XXX 027\XXX 021\XXX 028\XXX 014\XXX 024\XXX XXX\035 ....... ....... ....... ....... ....... ....... ....... XXXXXXX 007\034 ....... ....... ....... ....... ....... ....... XXX\043 ....... ....... ....... ....... ....... ....... ....... XXX\030 ....... ....... ....... ....... ....... ....... XXXXXXX
 

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>

using namespace std;

struct node {
    int r;
    int d;
    bool ok;
} a[111][111];

int b[111][111];

int n,m;
int num(int x) {
    if(x==0)return 1;
    int ans=0;
    while(x)
        ans++,x/=10;
    return 3-ans;
}

int main() {
    int t;
    cin>>t;
    while(t--) {
        char c;
        scanf("%d%d",&n,&m);
        memset(a,0,sizeof a);
        memset(b,0,sizeof b);
        for(int i=1; i<=n; i++) {
            for(int j=1; j<=m; j++) {
                scanf(" %c",&c);
                if(c=='_') {
                    a[i][j].ok=1;
                } else {
                    b[i][j]=c-'0';
                }
            }
        }
        for(int i=1; i<=n; i++) {
            for(int j=1; j<=m; j++) {

                if(a[i][j].ok) {
                    for(int k=j+1; k<=m; k++) {
                        if(a[i][k].ok)break;
                        a[i][j].r+=b[i][k];
                    }
                    for(int k=i+1; k<=n; k++) {
                        if(a[k][j].ok)break;
                        a[i][j].d+=b[k][j];
                    }
                }
            }
        }
        for(int i=1; i<=n; i++) {
            for(int j=1; j<=m; j++) {
                if(a[i][j].ok) {
                    if(a[i][j].d) {
                        int h=num(a[i][j].d);
                        for(int i=0; i<h; i++)
                            printf("0");
                        printf("%d",a[i][j].d);
                    } else
                        printf("XXX");
                    if(a[i][j].r==0&&a[i][j].d==0) {
                        printf("XXXX");
                    } else if(a[i][j].d&&a[i][j].r==0)
                        printf("\\XXX");
                    else{
                              printf("\\");
                        int h=num(a[i][j].r);
                        for(int i=0; i<h; i++)
                            printf("0");
                        printf("%d",a[i][j].r);
                    }
                } else if(b[i][j])
                    printf(".......");
                if(j!=m)printf(" ");
                else    printf("\n");
            }
        }
          printf("\n");
    }
    return 0;
}



 类似资料:

相关阅读

相关文章

相关问答