Editorial for Кръстословица


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.
by: maya

Тестовете можете да видите тук.

Примерно решение на C++:

#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

string mm="zzzzzzzzzzzzzzzzzzzzzzzzzzz";
void  min1(string s)
{
    int r;
    r=s.find("#");
    if (r==-1)
    {
        if (mm>s) mm=s;
        return;
    }

    while (s[0]=='#')
        s.erase(0,1); 

    if (s=="") 
        return;

    r=s.find('#');
    while (r!=-1 &&s !="")
    {   
        string s1=s.substr(0,r);
        if ( s1< mm && r>1)    
            mm=s1;
        s.erase(0,r+1);
        r=s.find('#');
    }
    if (s!="" && s<mm && s.size()>1) 
        mm=s;  
}

int main()
{
    string s[20],s1[20];
    int m,n;
    cin>>n>>m;
    for (int i=0; i<n;i++) cin>>s[i];
    for (int i=0;i<m; i++)
    {
        s1[i]="";
        for (int j=0; j<n; j++)
           s1[i] =s1[i]+s[j][i];
    }

    for (int i=0; i<n;i++) 
        min1(s[i]);
    for (int i=0; i<m;i++) 
        min1(s1[i]);

    cout<<mm<<endl;
    return 0;
}

Comments

There are no comments at the moment.