Cod sursa(job #660397)
| Utilizator | Data | 12 ianuarie 2012 21:40:56 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <fstream>
#include <string>
using namespace std;
int main()
{
int n, m;
bool k=true;
string v;
fstream f("elmaj.in", ios::in);
f >> n;
m=n;
for(int i=0; i<n; i++)
f >> v[i];
f.close();
f.clear();
while(k)
{
k=false;
m--;
for(int i=0; i<m; i++)
if(v[i]>v[i+1])
{
k=true;
swap(v[i], v[i+1]);
}
}
f.open("elmaj.out", ios::out);
for(int i=0; i<n/2; i++)
if(v[i]==v[i+n/2])
f << v[i] << endl;
f.clear();
f.close();
system("pause");
}