Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><pre> include // std::cout include // std::sort include // std::vector</p> <p>int getYear(int date) { int year = (date / 10000);</p> <p>return (year &lt; 20) ? 2000+year : year;</p> <p>} int getMonth(int date) {</p> <p>int month = (date / 100) % 100; return (date /100) % 100;</p> <p>} int getDay(int date) { int d2 = (date /10) % 10; int d1 = (date /100) % 10;</p> <p>return d2*10+d1;</p> <p>} bool myfunction (int i,int j) {</p> <p>if (getYear(i) > getYear(j)) return true; if (getYear(i) == getYear(j) &amp;&amp; getMonth(i) > getMonth(j)) return true; if (getYear(i) == getYear(j) &amp;&amp; getMonth(i) == getMonth(j) &amp;&amp; getDay(i) > getDay(j)) return true; return false; }</p> <p>int main () { int myints[] = {130525,951022 , 130624, 121212};</p> <code> std::vector&lt;int&gt; myvector (myints, myints+4); std::sort (myvector.begin(), myvector.end(), myfunction); std::cout &lt;&lt; "Year: " &lt;&lt; getYear(130525); std::cout &lt;&lt; "Month:" &lt;&lt; getMonth(130525); std::cout &lt;&lt; "Day:" &lt;&lt; getDay(130525); std::cout &lt;&lt; std::endl &lt;&lt;std::endl; std::cout &lt;&lt; "Year: " &lt;&lt; getYear(951022); std::cout &lt;&lt; "Month:" &lt;&lt; getMonth(951022); std::cout &lt;&lt; "Day:" &lt;&lt; getDay(951022); std::cout &lt;&lt; std::endl; std::cout &lt;&lt; "myvector contains:"; for (std::vector&lt;int&gt;::iterator it=myvector.begin(); it!=myvector.end(); ++it) std::cout &lt;&lt; ' ' &lt;&lt; *it; std::cout &lt;&lt; '\n'; return 0; } </code></pre> <p>Made a boo boo, this is correct updated pastebin <a href="http://pastebin.com/yvBNrcTU" rel="nofollow">http://pastebin.com/yvBNrcTU</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload