ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1496. Spammer

I got the solution answer
Posted by Muzaffardjan Karaev 16 Oct 2013 20:51
https://uzdisk.uz/public.php?service=files&token=dacc643443b8fa3475306cd6b57a9277a6d354a5&file=/acm.timus.ru/1496.%20%D0%A1%D0%BF%D0%B0%D0%BC%D0%B5%D1%80.cpp

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

int n;
string array[10001];

struct TSpamer
{
    string name;
    short index;
}Spamer[10001];

void my_sort(int j)
{
    int ind = 0;
    int Min_element = Spamer[ind].index;

    for(int i=0; i<j; i++)
    {
        int l = 0;
        while(l < j)
        {
            if(Spamer[l].index <= Min_element)
            {
                Min_element = Spamer[l].index;
                ind = l;
            }
            l++;
        }

        cout << Spamer[ind].name << endl;
        Min_element = 101;
        Spamer[ind].index = 102;
    }

    return;
}

int main(void)
{
    int counter = 1;

    cin >> n;
    for(int i=0; i<n; i++)
        cin >> array[i];
    sort(array, array+n);

    int k = 0, j = 0;
    while(k < n-1)
    {
        for(int i=k+1; i<n; i++)
            if(array[k] == array[i])
                counter++;

        if(counter > 1)
        {
            Spamer[j].index = counter;
            Spamer[j].name = array[k];
            j++;
        }

        k += counter;
        counter = 1;
    }

    my_sort(j);

    return 0;
}

Edited by author 16.10.2013 20:53
Re: I got the solution answer
Posted by Grandmaster 20 Feb 2015 15:12
check my sol :P
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main () {
    string a[103];
    set<string> gh;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)cin >> a[i];
        for(int i = 0; i < n - 1; i++){
            for(int j = i + 1; j < n; j++)
                if(a[i] == a[j]){gh.insert(a[i]);}
    }
    while (!gh.empty()){
           cout << *gh.begin() << "\n";
        gh.erase(gh.begin());}
}

Edited by author 20.02.2015 15:18