欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

UVa 201 - Squares

程序员文章站 2022-03-30 08:25:46
...

   卡了我两天。用各种循环,标号把我弄晕了,好不容易做出来以后输出的两个数弄反了。



#include<iostream>
#include<cstring>
using namespace std;

int H[15][15], V[15][15];
void squares(char line, int i, int j){
    if(line == 'H')
        H[i][j] = 1;
    if(line == 'V')
        V[i][j] = 1;
}
int main(){
    int m, n, a, b, time = 0;
    while(cin >> n >> m){
        char line;
        int IS_OK = 1;
        while(m--){
            cin >> line >> a >> b;
            squares(line, a, b);
        }
        if(time++)
            cout << endl
            << "**********************************"
            << endl << endl;
        cout << "Problem #" << time
        << endl << endl;
        for(int size = 1; size < n; size++){
                int count_ = 0;
                for(int i = 1; i <= n - size; i++)
                    for(int j = 1; j <= n - size; j++){
                            int sign = 1;
                        for(int p = j; p < j + size; p++){
                            if(H[i][p] != 1|| H[i + size][p] != 1){
                                sign = 0;
                                break;
                            }
                        }
                        if(sign)
                            for(int p = i; p < i + size; p++){
                                if(V[j][p] != 1|| V[j + size][p] != 1){
                                    sign = 0;
                                    break;
                            }
                        }
                        if(sign){
                            count_++;
                            IS_OK = 0;
                        }
                }
            if(count_)
                cout << count_
                << " square (s) of size "
                << size << endl;
        }
        if(IS_OK)
            cout << "No completed squares can be found." << endl;
        memset(H, 0, sizeof(H));
        memset(V, 0, sizeof(V));
    }
    return 0;
}