Skip to content

Instantly share code, notes, and snippets.

@jaideepheer
Last active April 13, 2019 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaideepheer/8c21a10bc90df4477384c0f3fdbd4657 to your computer and use it in GitHub Desktop.
Save jaideepheer/8c21a10bc90df4477384c0f3fdbd4657 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<bitset>
using namespace std;
int main()
{
int N;
cin>>N;
unsigned int count[4096] = {0};
long long inp;
long answer = 0;
for(int i=0; i<N; ++i)
{
int hash = 0;
cin>>inp;
// hash digits
while(inp>0)
{
hash |= 1<<(inp%10);
inp /= 10;
}
++count[hash];
answer += count[hash ^ (0b1111111111)];
//cout<<bitset<10>(hash)<<" | "<<bitset<10>(hash ^ (0b1111111111))<<endl;
}
cout<<answer<<endl;
return 0;
}
import java.io.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
class balak
{
int marks;
int id;
String name;
public int getnamelen(){return this.name.length();}
public int getmark(){return this.marks;}
public int getid(){return this.id;}
@Override
public String toString() {
return "[Balak] id: "+this.id+", name: "+this.name+", marks: "+(-this.marks);
}
}
public class sort
{
public static void main(String args[])
{
Scanner s = new Scanner(System.in);
List<balak> lols = new ArrayList<>();
int N = s.nextInt();
// memory alloc
for(int i=0;i<N;++i)
{
lols.add(new balak());
}
// Take input
for(int i=0;i<N;++i) lols.get(i).name = s.next();
for(int i=0;i<N;++i) lols.get(i).marks = -s.nextInt();
for(int i=0;i<N;++i) lols.get(i).id = s.nextInt();
// sort
Comparator<balak> comp = Comparator.comparing(balak::getmark).thenComparing(balak::getnamelen).thenComparing(balak::getid);
lols.sort(comp);
for(int i=0;i<N;++i)
{
System.out.println(lols.get(i));
}
s.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment