Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // largestString.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- using Iterator = std::string::iterator;
- bool lexicographic_compare(Iterator first1, Iterator last1,
- Iterator first2, Iterator last2);
- string getString(vector<string> pile);
- int main() {
- // string input
- int N = 0;
- cin >> N;
- if (N <= 0)
- return 0;
- vector<string> pile (N);
- for (int i = 0; i < N; ++i)
- {
- string input;
- //getline(cin, input);
- cin >> input;
- pile.at(i) = input;
- }
- string large = getString(pile);
- cout << large << "\n";
- return 0;
- }
- bool lexicographic_compare(Iterator first1, Iterator last1,
- Iterator first2, Iterator last2)
- {
- Iterator j = first2;
- for (Iterator i = first1; i != last1; ++i)
- {
- if (j == last2)
- return false;
- if (*i < *j)
- return true;
- if (*i == *j)
- {
- ++j;
- continue;
- }
- else
- return false;
- ++j;
- }
- Iterator k = first1;
- for (Iterator i = first2; i != last2; ++i)
- {
- if (j == last1)
- return true;
- if (*i < *j)
- return false;
- if (*i == *j)
- {
- ++k;
- continue;
- }
- else
- return false;
- ++k;
- }
- return false;
- }
- string getString(vector<string> pile)
- {
- string large = pile.at(0);
- for (unsigned int i = 0; i < pile.size() - 1; ++i)
- {
- string name2 = pile.at(i + 1);
- if (lexicographic_compare(large.begin(), large.end(), name2.begin(), name2.end()))
- {
- large = pile.at(i + 1);
- }
- }
- return large;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement