Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. // largestString.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <string>
  7. #include <vector>
  8.  
  9.  
  10. using namespace std;
  11. using Iterator = std::string::iterator;
  12.  
  13. bool lexicographic_compare(Iterator first1, Iterator last1,
  14. Iterator first2, Iterator last2);
  15.  
  16. string getString(vector<string> pile);
  17.  
  18. int main() {
  19. // string input
  20. int N = 0;
  21. cin >> N;
  22.  
  23. if (N <= 0)
  24. return 0;
  25.  
  26. vector<string> pile (N);
  27.  
  28. for (int i = 0; i < N; ++i)
  29. {
  30. string input;
  31. //getline(cin, input);
  32. cin >> input;
  33. pile.at(i) = input;
  34. }
  35.  
  36. string large = getString(pile);
  37.  
  38. cout << large << "\n";
  39.  
  40. return 0;
  41. }
  42.  
  43. bool lexicographic_compare(Iterator first1, Iterator last1,
  44. Iterator first2, Iterator last2)
  45. {
  46.  
  47. Iterator j = first2;
  48.  
  49. for (Iterator i = first1; i != last1; ++i)
  50. {
  51. if (j == last2)
  52. return false;
  53.  
  54. if (*i < *j)
  55. return true;
  56.  
  57. if (*i == *j)
  58. {
  59. ++j;
  60. continue;
  61. }
  62.  
  63. else
  64. return false;
  65.  
  66. ++j;
  67. }
  68.  
  69. Iterator k = first1;
  70.  
  71. for (Iterator i = first2; i != last2; ++i)
  72. {
  73. if (j == last1)
  74. return true;
  75.  
  76. if (*i < *j)
  77. return false;
  78.  
  79. if (*i == *j)
  80. {
  81. ++k;
  82. continue;
  83. }
  84.  
  85. else
  86. return false;
  87.  
  88. ++k;
  89. }
  90. return false;
  91. }
  92.  
  93. string getString(vector<string> pile)
  94. {
  95. string large = pile.at(0);
  96.  
  97. for (unsigned int i = 0; i < pile.size() - 1; ++i)
  98. {
  99.  
  100. string name2 = pile.at(i + 1);
  101.  
  102. if (lexicographic_compare(large.begin(), large.end(), name2.begin(), name2.end()))
  103. {
  104. large = pile.at(i + 1);
  105. }
  106.  
  107. }
  108. return large;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement