https://www.codechef.com/viewsolution/37967262
I have sorted by year then month and then day. Why do I get ‘wrong answer’?
Please help!
https://www.codechef.com/viewsolution/37967262
I have sorted by year then month and then day. Why do I get ‘wrong answer’?
Please help!
Wait for the contest to get over
I know its not allowed, but since its not an important contest, so I am just telling you some probable mistakes.
I have spent a lot of time on this problem but can’t find a fault.
I did give endl and sort does sorting of tuple this way only.
It’s running fine on my local.
It’s so frustrating, at least one testcase should be shown for a sanity check.
Sort using comparator by making pair of pairs. Its very simple
https://www.codechef.com/viewsolution/37971538
Now I used comparator also.
I have no idea which case is not working.
I can’t see your code until contest ends. Better put a Gfg or Ideone link
/* author: Mohammad Sheraj */
/* Clang++17 launch.json for debugger */
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// char buf[10]; fgets(buf, 10, stdin);
// Use long long instead of long
// always use long long for answer
// cout<<"Case #"<<test_case<<": "<<answer<<endl;
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
//////////////
// cout.precision(17);cout<<fixed<<answer<<endl;
// printf("%.2lf",double_value);
///////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <stack>
#include <queue> //includes priority_queue
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <set> //sorts by value
#include <map> //sorts by key
#include <algorithm> //max/min //lower_bound/upper_bound //binary_search //reverse //transform //next_permutation
#include <math.h> //ceil/floor
// #include <numeric> //gcd //there will be sqiggly red line but no compilation error
// #include <time.h> //clock_t clock() //CLOCKS_PER_SEC
// #include <chrono>
// #include <thread>
using namespace std;
/////////////////////////////////////////////////////////////////////////
bool compare(tuple<int,int,int> a,tuple<int,int,int> b) {
if(get<0>(a)<get<0>(b)) {
return true;
} else if(get<0>(a)>get<0>(b)) {
return false;
} else {
if(get<1>(a)<get<1>(b)) {
return true;
} else if(get<1>(a)>get<1>(b)) {
return false;
} else {
if(get<2>(a)<=get<2>(b)) {
return true;
} else if(get<2>(a)>get<2>(b)) {
return false;
}
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef SHERAJ
freopen("input.txt" , "r", stdin);
#endif
// int T;
// cin>>T;
// for(int test_case=1;test_case<=T;test_case++) {
// }
int n;
cin>>n;
vector<tuple<int,int,int>> s(n);//year month day
for(int i=0;i<n;i++) {
fscanf(stdin,"%d/%d/%d\n",&get<2>(s[i]),&get<1>(s[i]),&get<0>(s[i]));
}
sort(s.begin(),s.end(),compare);
for(int i=0;i<n;i++) {
cout<<get<2>(s[i])<<"/"<<get<1>(s[i])<<"/"<<get<0>(s[i])<<endl;
}
return 0;
}