ACM Timus 1496. Spammer

Problem Link: 1496. Spammer

 

 


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

using namespace std;

int main()
{
    int n;
    int i,j,k,o,p;

    scanf("%d",&n);

    string s[n];

    for(i=0;i<n;i++)
        cin >> s[i];

    string x[n],y;

    p=0;

    for(i=0;i<n;i++){

        if(i==n-1)
            j=i;
        else
            j=i+1;

        k=0;

        for(;j<n;j++){

            if(s[i].compare(s[j])==0){
                k=1;
                break;
            }
        }
        if(k=1){
            y=s[i];

            o=0;

            for(j=0;j<i;j++){
                if(y.compare(x[j])==0)
                    o=1;
            }

            if(o==0){

                x[p]=y;
                p++;
            }
        }

    }

    sort(x,x+p);

    for(i=0;i<p;i++){

        o=0;

        for(j=0;j<n;j++){

            if(x[i].compare(s[j])==0){
                o++;
                if(o>1){
                    cout << x[i] << endl;
                    break;
                    }

            }
        }
    }

    return 0;
}

Advertisements