Showing posts with label sort. Show all posts
Showing posts with label sort. Show all posts

Monday, September 16, 2019

Codeforce A. The Child and Homework

  1. #include< iostream >
  2. #include< cstdio >
  3. #include< algorithm >
  4.  
  5. using namespace std;
  6.  
  7. string o[4];
  8.  
  9. int main() {
  10.  
  11. int maxlength = 0, minlength = 110, maxindex = 0, minindex = 0;
  12.  
  13. int c[4];
  14.  
  15. for (int i = 0; i < 4; i++) {
  16. getline(cin, o[i]);
  17. c[i] = o[i].length() - 2;
  18. }
  19.  
  20. sort(c, c + 4);
  21.  
  22. bool hasMax = c[3] >= c[2] * 2;
  23. bool hasMin = c[0] <= c[1] / 2;
  24.  
  25. if (hasMax == hasMin) {
  26. cout << "C";
  27. } else if (hasMin) {
  28. for (int i = 0; i < 4; i++) {
  29. if (c[0] + 2 == o[i].length()) {
  30. cout << o[i].at(0);
  31. }
  32. }
  33. } else if (hasMax) {
  34. for (int i = 0; i < 4; i++) {
  35. if (c[3] + 2 == o[i].length()) {
  36. cout << o[i].at(0);
  37. }
  38. }
  39. }
  40.  
  41. return 0;
  42. }

Friday, April 7, 2017

Uri 2252 - Discovering Password

#include <bits/stdc++.h>
using namespace std;
typedef long double LD;

template
struct less_first {
    typedef pair < T1, T2 > type;
    bool operator ()(type const& a, type const& b) const {
        return a.first > b.first;
    }
};

int main()
{
    //freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n,c = 0;
    while(cin >> n){
        map < LD, int > ans;
        LD a;
        for(int i = 0; i < 10 ;i++) {
                cin >> a;
         while(ans.count(a) != 0){
            a -= (LD)1e-15;
         }
        ans.insert(pair < LD,int > (a,i));
        }
     vector < pair < LD, int > > ans1(ans.begin(), ans.end());
     sort(ans1.begin(), ans1.end(), less_first < LD, int > ());
     vector > :: iterator it = ans1.begin();

     int i = 0;
     cout << "Caso " << ++c << ": ";
     for( vector < pair < LD, int > > :: iterator it = ans1.begin() ; it != ans1.end() ;it++,i++){
        if(i == n) break;
        cout << it->second ;
     }
        cout << endl;
    }
    return 0;
}