import math
t = int(input())
for _ in range(t):
a1, a2, a3, c1, c2, c3 = [int(x) for x in input().strip().split(" ")]
if (a1 > a2 and c1 > c2) or (a1 == a2 and c1 == c2) or (a1 < a2 and c1 < c2):
if (a1 > a3 and c1 > c3) or (a1 == a3 and c1 == c3) or (a1 < a3 and c1 < c3):
if (a2 > a3 and c2 > c3) or (a2 == a3 and c2 == c3) or (a2 < a3 and c2 < c3):
print ("FAIR")
else:
print ("NOT FAIR")
else:
print ("NOT FAIR")
else:
print ("NOT FAIR")
overkill solution
import java.util.;
import java.io.;
import java.math.;
import java.util.regex.;
import static java.lang.System.*;
CodeChef: Practical coding for everyone
public class Main{
static long start, stop, mod = (long) 1e9 + 7L;
static void debug(Object... a){
err.println(Arrays.deepToString(a));
}
static void starttime(){start = currentTimeMillis();}
static void stoptime(){stop = currentTimeMillis();}
static void gettime(){err.println(((double)(stop - start) / 1000.0) + " seconds");}
static class FastReader{
StringTokenizer st;
BufferedReader br;
FastReader(){
br = new BufferedReader(new InputStreamReader(in));
}
String n(){
while(st == null || !st.hasMoreElements()){
try{
st = new StringTokenizer(br.readLine());
}
catch(Exception e){
e.printStackTrace();
}
}
return st.nextToken();
}
int ni(){
return Integer.parseInt(n());
}
float nf(){
return Float.parseFloat(n());
}
double nd(){
return Double.parseDouble(n());
}
long nl(){
return Long.parseLong(n());
}
String ns(){
String k="";
try{
k = br.readLine();
}
catch(Exception e){
e.printStackTrace();
}
return k;
}
}
static class pair<First extends Comparable<? super First>,
Second extends Comparable<? super Second>> implements Comparable<pair<First, Second>>{
public First first;
public Second second;
pair(First first,Second second){
this.first = first;
this.second = second;
}
public First getFirst(){
return this.first;
}
public Second getSecond(){
return this.second;
}
public void setFirst(First first){
this.first = first;
}
public void setSecond(Second second){
this.second = second;
}
@Override
public String toString(){
return "[" + first + " " + second + "]";
}
@Override
public int compareTo(pair<First, Second> pair){
int res = this.first.compareTo(pair.first);
return res == 0 ? this.second.compareTo(pair.second) : res;
}
@Override
public boolean equals(Object o){
if(this == o)
return true;
if(o == null || getClass() != o.getClass())
return false;
pair<?,?> pair = (pair<?, ?>) o;
if(!first.equals(pair.first)) return false;
return second.equals(pair.second);
}
@Override
public int hashCode(){
return 31 * first.hashCode() + second.hashCode();
}
}
public static void main(String args[]) throws IOException{
FastReader in = new FastReader();
starttime();
solve(in);
stoptime();
//gettime();
}
static void solve(FastReader in){
int t = in.ni();
while(t-- > 0){
pair[] agesAndMoney = new pair[3];
for(int i = 0; i < agesAndMoney.length; i++) agesAndMoney[i] = new pair<Integer, Integer>(in.ni(), 0);
for(int i = 0; i < agesAndMoney.length; i++) agesAndMoney[i].setSecond(in.ni());
Arrays.sort(agesAndMoney);
int max = Integer.MIN_VALUE;
String output = "FAIR";
for(int i = 0; i < agesAndMoney.length - 1; i++){
int first = agesAndMoney[i].getFirst().compareTo(agesAndMoney[i + 1].getFirst());
int second = agesAndMoney[i].getSecond().compareTo(agesAndMoney[i + 1].getSecond());
//System.out.println(first + " " + second);
if((first == 0 && second != 0) ||
(first < 0 && second >= 0) ||
(first > 0 && second <= 0)){
output = "NOT FAIR";
break;
}
}
System.out.println(output);
}
}
}
Hi , this my code , and i really donât know why its wrong ⌠Please help me out!!
#include<bits/stdc++.h>
using namespace std;
class child
{
public:
int age,money;
};
bool sortAge(child &a, child &b)
{
return (a.age<b.age);
}
int main()
{
int tc;
cin>>tc;
while(tc--)
{
vector<child>c;
int arr[6];
for(int i=0;i<6;i++)
cin>>arr[i];
for(int i=0;i<3;i++)
{
child j;
j.age=arr[i];
j.money=arr[i+3];
c.push_back(j);
}
//c.sort(sortAge);
sort(c.begin(),c.end(),sortAge);
//for(int i=0;i<3;i++)
// cout<<c[i].age<<" "<<c[i].money<<endl;
int flag=0;
for(int i=0;i<2;i++)
{
if((c[i].age==c[i+1].age)&&(c[i].money!=c[i+1].money))
{
cout<<"NOT FAIR\n";
flag=1;
break;
}
else if(c[i].money > c[i+1].money)
{
cout<<"NOT FAIR\n";
flag=1;
break;
}
}
if(flag==0)
cout<<"FAIR\n";
flag=0;
}
}
Please format your code or link to a solution - this has been mangled by the forum software and is uncompilable. Thanks!
Edit:
Thankyou - your code fails the following testcase:
1
12 4 6 29 24 29
Why this code is giving wrong answer
#include <iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<map>
#include<string>
#include<string.h>
#include<math.h>
#define REP(i, a, b) for (int i = int(a); i <= int(b); i++)
#define NREP(i, a, b) for (int i = int(a); i >= int(b); i--)
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define circ_inc(i, n) (i + 1) % int(n)
#define circ_dec(i, n) (i + int(n) - 1) % int(n)
#define round(x) (int)((double)int(x) + 0.5)
#define println(x) cout << x << '\n'
#define F first
#define S second
#define INF 1000000000
#define gcd __gcd
#define nset __builtin_popcount
#define pb push_back
#define btoe(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vector<int> > vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef map<string, int> msi;
typedef istringstream iss;
int main()
{
FASTIO;
int t;
cin >> t;
while (t--) {
vi v1(4);//age array
vi v2(4);//gift array4
REP(i, 1, 3)
cin >> v1[i];
int v1_min = 0, v1_max = 0;
v1_min = *min_element(v1.begin()+1, v1.end());
v1_max = *max_element(v1.begin()+1, v1.end());
REP(i, 1, 3)
cin >> v2[i];
int v2_min = 0, v2_max = 0;
v2_min = *min_element(v2.begin()+1, v2.end());
v2_max = *max_element(v2.begin()+1, v2.end());
int temp = 0;
if (v1_min != v1_max) {
REP(i, 1, 3) {
if (v1[i] == v1_min && v2[i] == v2_min)
temp++;
else if (v1[i] == v1_max && v2[i] == v2_max)
temp++;
else if (v1[i] > v1_min && v1[i] < v1_max && v2[i] != v2_min && v1[i] != v2_max)
temp++;
}
if (temp == 3)
cout << "FAIR" << endl;
else
cout << "NOT FAIR" << endl;
}
else
{
if (std::adjacent_find(v2.begin() + 1, v2.end(), std::not_equal_to<>()) == v2.end())
{
cout << "FAIR" << endl;
}
else
cout << "NOT FAIR" << endl;
}
}
return 0;
}
Please format your code or link to a solution - this has been mangled by the forum software and is uncompilable. Thanks!
thanks . i did .
Thank you so much for replying . I will try to resolve the mistake in my code .
@ssjgz just to clarify, i am getting output as FAIR for the test case you mentionedâŚIs it not the correct output? Thankyou
No âfairâ is not the correct answer since age of first kid nd last kid are not same but both are getting equal cash.
Ooh I get it now !!! Thanks a lot!!
Whats wrong in this code::
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
cin >> T;
while (T--) {
int a1, a2, a3, c1, c2, c3;
cin >> a1 >> a2 >> a3 >> c1 >> c2 >> c3;
vector<pair<int, int>> vect;
vect.push_back(make_pair(a1, c1));
vect.push_back(make_pair(a2, c2));
vect.push_back(make_pair(a3, c3));
sort(vect.begin(), vect.end());
string ans;
for (int i = 0; i < 2; i++) {
if (vect[i].first == vect[i + 1].first) {
if (vect[i].second == vect[i + 1].second) {
ans = "FAIR";
} else {
ans = "NOT FAIR";
break;
}
} else if (vect[i].second < vect[i + 1].second) {
ans = "FAIR";
} else {
ans = "NOT FAIR";
break;
}
}
std::cout << ans << '\n';
}
return 0;
}
It fails for the following testcase:
1
17 1 9 75 29 37
@ssjgz Thanks for your quick reply. But I canât figure out whatâs wrong here. it should be FAIR right??
Yes. Sorry, youâve given me two bits of code and I donât know which Iâm supposed to be looking at
You gave the linked solution: CodeChef: Practical coding for everyone
and copy-n-pasted the solution:
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
cin >> T;
while (T--) {
int a1, a2, a3, c1, c2, c3;
cin >> a1 >> a2 >> a3 >> c1 >> c2 >> c3;
vector<pair<int, int>> vect;
vect.push_back(make_pair(a1, c1));
vect.push_back(make_pair(a2, c2));
vect.push_back(make_pair(a3, c3));
sort(vect.begin(), vect.end());
string ans;
for (int i = 0; i < 2; i++) {
if (vect[i].first == vect[i + 1].first) {
if (vect[i].second == vect[i + 1].second) {
ans = "FAIR";
} else {
ans = "NOT FAIR";
break;
}
} else if (vect[i].second < vect[i + 1].second) {
ans = "FAIR";
} else {
ans = "NOT FAIR";
break;
}
}
std::cout << ans << '\n';
}
return 0;
}
both of which are different. Which is the one you do want to be checked?
Edit:
Just seen your edit - the new code thatâs copy-n-pasted appears to work OK, for me - it passes 10â000 randomised tests, at least!
Yes!!! Itâs AC when I replace read(T) with cin >> T
read(T) defined as follow::
template <class T> void read(T &x) {
int f = 0;
x = 0;
char s = getchar();
while (s < '0' || s > '9') {
if (s == '-')
f = 1;
s = getchar();
}
while (s >= '0' && s <= '9') {
x = (x << 3) + (x << 1) + (s ^ 48);
s = getchar();
}
x = f ? -x : x;
}
Isnât read(T) equals cin >> T??
Iâm not sure, whatâs the different here?? Can you please explain it?
Anyway, many many thanks for helping
Here is my solution to this problem it establish relation between two elements of an array and put the relationship in a third array and at last compares the relationship arrays
https://www.codechef.com/viewsolution/26177703
No, youâre mixing a C-style input method (getchar
) with C++ style (cin
), but youâve called ios_base::sync_with_stdio(false)
so they conflict.
Edit:
May as well post my solution - weâre given two simple rules to check for violations of; not sure why people are over-complicating things so much
It doesnt work for this test case.
1
7 7 4 8 8 8