注册 登录
编程论坛 C语言论坛

请问我写的有什么问题吗,求解

Limetence 发布于 2020-10-13 09:58, 1070 次点击
只有本站会员才能查看附件,请 登录

# include<stdio.h>
int main(){
    int n,m,h,x,y,o,p,g,f,q,w;
    int max[1000];
    int min[1000];
    scanf("%d%d",&n,&m);
    h=n*m;
    int shen[100000];
    while(h--){
     scanf("%d",&shen[n*m-h]);
    }
    o=m;
    p=n;
    while(m--){
        max[o-m]=shen[o-m];
        g=2*o-m;
        q=o-m;
        while(n-=1)
        {
        if(shen[g]>shen[q]){
        
        max[o-m]=shen[g];
        q=g;}
        g+=o;
    }}
    while(n--){
        min[p-n]=shen[p-n];
        g=p-n+1;
        w=p-n;
        while(m-=1){
        if(shen[g]<shen[w]){
        min[p-n]=shen[g];
        w=g;}
        g++;
}
    }
    while(m--){
        while(n--){
            if(max[m+1]==min[n+1])
            {x=m+1;
            y=n+1;
            }
        }
    }
    printf("(%d,%d)",x,y);
}
2 回复
#2
rjsp2020-10-13 11:34
变量太多,看不懂

程序代码:
#include <stdio.h>

int main( void )
{
    unsigned n, m;
    scanf( "%u%u", &n, &m );

    unsigned min_idxs_byrow[100]={0}, min_vals_byrow[100]={0};
    unsigned max_idxs_bycol[100]={0}, max_vals_bycol[100]={0};

    for( unsigned i=0; i!=n*m; ++i )
    {
        unsigned deepth;
        scanf( "%u", &deepth );

        if( ~0u-deepth > min_vals_byrow[i/m] )
        {
            min_idxs_byrow[i/m] = i%m;
            min_vals_byrow[i/m] = ~0u-deepth;
        }

        if( deepth > max_vals_bycol[i%m] )
        {
            max_idxs_bycol[i%m] = i/m;
            max_vals_bycol[i%m] = deepth;
        }
    }

    for( unsigned i=0; i!=n; ++i )
    {
        if( max_idxs_bycol[min_idxs_byrow[i]] == i )
            printf( "(%u,%u)\n", i+1, min_idxs_byrow[i]+1 );
    }
}
#3
Limetence2020-10-13 12:02
回复 2楼 rjsp
我化简了一下,你用的函数我都看不懂,难受
# include<stdio.h>
int main(){
    int n,m,h,x,y,o,p,g;//g是用来循环的,在南北是下一行然后一行一行加,东西一个一个加;o,p用来保存行数列数
    int max[100];
    int min[100];
    scanf("%d%d",&n,&m);
    h=n*m;
    int shen[10000];
    while(h--){
     scanf("%d",&shen[n*m-h]);
    }
    o=m;
    p=n;
    while(m--){
        max[o-m]=shen[o-m];
        g=2*o-m;
        while(n-=1)
        {
        if(shen[g]>max[o-m])
        max[o-m]=shen[g];
        g+=o;
    }}
    while(n--){
        min[p-n]=shen[p-n];
        g=p-n+1;
        while(m-=1){
        if(shen[g]<min[p-n])
        min[p-n]=shen[g];
        g++;
}
    }
    while(m--){
        while(n--){
            if(max[m+1]==min[n+1])
            {x=m+1;
            y=n+1;
            }
        }
    }
    printf("(%d,%d)",x,y);
}
1