Last active
September 25, 2015 13:13
-
-
Save lantoli/a290af048e27edb6d4dd to your computer and use it in GitHub Desktop.
Studious Student
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import java.io.PrintStream; | |
import java.util.Arrays; | |
import java.util.Scanner; | |
public class StudiousStudentWrong { | |
public static void main(String[] args) throws Exception { | |
System.setIn(new FileInputStream("studious_student.in")); | |
System.setOut(new PrintStream(new FileOutputStream("studious_student.first_try"))); | |
try (Scanner in = new Scanner(System.in)) { | |
int tests = in.nextInt(); | |
in.nextLine(); | |
for (long test = 1; test <= tests; test++) { | |
in.nextInt(); | |
String[] str = in.nextLine().split(" "); | |
Arrays.sort(str); | |
for (String s : str) { | |
System.out.print(s); | |
} | |
System.out.println(); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import java.io.PrintStream; | |
import java.util.Arrays; | |
import java.util.Comparator; | |
import java.util.Scanner; | |
public class StudiousStudent { | |
public static void main(String[] args) throws Exception { | |
System.setIn(new FileInputStream("studious_student.in")); | |
System.setOut(new PrintStream(new FileOutputStream("studious_student.good"))); | |
try (Scanner in = new Scanner(System.in)) { | |
int tests = in.nextInt(); | |
in.nextLine(); | |
for (long test = 1; test <= tests; test++) { | |
in.nextInt(); | |
String[] str = in.nextLine().split(" "); | |
Comparator<String> comparator = new Comparator<String>() { | |
@Override | |
public int compare(String a, String b) { | |
return (a + b).compareTo(b + a); | |
} | |
}; | |
Arrays.sort(str, comparator); | |
for (String s : str) { | |
System.out.print(s); | |
} | |
System.out.println(); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import java.io.PrintStream; | |
import java.util.Arrays; | |
import java.util.Scanner; | |
import java.util.stream.Collectors; | |
public class StudiousStudent8 { | |
public static void main(String[] args) throws Exception { | |
System.setIn(new FileInputStream("studious_student.in")); | |
System.setOut(new PrintStream(new FileOutputStream("studious_student.good"))); | |
try (Scanner in = new Scanner(System.in)) { | |
int tests = in.nextInt(); | |
in.nextLine(); | |
for (long test = 1; test <= tests; test++) { | |
in.nextInt(); | |
System.out.println(Arrays.stream(in.nextLine().split(" ")). | |
sorted((a, b) -> (a + b).compareTo(b + a)). | |
collect(Collectors.joining(""))); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
namespace Kata | |
{ class StudiousStudent | |
{ | |
static void Main(string[] args) { | |
const string filename = @"..\..\studious_prod"; | |
using (var input = File.OpenText(filename + ".in")) | |
using (var output = File.CreateText(filename + ".out")) { | |
new StudiousStudent().Process(input, output); | |
} | |
} | |
private static IComparer<string> comparer = Comparer<string>.Create( | |
(a, b) => (a+b).CompareTo(b+a)); | |
public void Process(TextReader input, TextWriter output) | |
{ | |
int tests = int.Parse(input.ReadLine()); | |
for (var test = 0; test < tests; test++) { | |
output.WriteLine(String.Join("", input.ReadLine().Split().Skip(1).OrderBy(n => n, comparer))); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <algorithm> | |
using namespace std; | |
bool comparer(const string &a, const string &b) { return a+b < b+a; } | |
void main() | |
{ | |
freopen("studious_student.in", "rt", stdin); | |
freopen("studious_student.out", "wt", stdout); | |
int N,M; | |
string words[10]; | |
cin >> N; | |
for (auto test = 0; test < N; test++) { | |
cin >> M; | |
for (auto i = 0; i < M; i++) | |
cin >> words[i]; | |
sort(words, words + M, comparer); | |
for (auto i = 0; i < M; i++) | |
cout << words[i]; | |
cout << endl; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <algorithm> | |
#include <functional> | |
using namespace std; | |
void main() | |
{ | |
freopen("studious_student.in", "rt", stdin); | |
freopen("studious_student.out", "wt", stdout); | |
int N,M; | |
string w[10]; | |
cin >> N; | |
for (auto test = 0; test < N; test++) { | |
cin >> M; | |
for (auto i = 0; i < M; i++) | |
cin >> w[i]; | |
sort(w, w + M, [](const string& a, const string& b) { return a+b < b+a; }); | |
for (auto i = 0; i < M; i++) | |
cout << w[i]; | |
cout << endl; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python2 | |
FILENAME = "example" | |
import sys | |
sys.stdin = open(FILENAME + ".in", 'r') | |
sys.stdout = open(FILENAME + ".out", 'w') | |
def solve(line): | |
return ''.join( sorted(line.split()[1:], cmp = lambda a,b: cmp(a+b, b+a)) ) | |
def get_line(): return raw_input() | |
def get_int(): return int(get_line()) | |
if __name__ == '__main__': | |
for case in range(get_int()): | |
print(solve(get_line())) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
FILENAME = "studious_student" | |
import sys | |
sys.stdin = open(FILENAME + ".in", 'r') | |
sys.stdout = open(FILENAME + ".out", 'w') | |
from functools import cmp_to_key | |
def solve(line): | |
return ''.join( sorted(line.split()[1:], key=cmp_to_key(cmp_join_str)) ) | |
def cmp(a,b): return (a > b) - (a < b) | |
def cmp_join_str(a,b): return cmp(a+b, b+a) | |
def get_line(): return input() | |
def get_int(): return int(get_line()) | |
if __name__ == '__main__': | |
for case in range(get_int()): | |
print(solve(get_line())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python2 | |
for _ in range(int(raw_input())): | |
print(''.join( sorted(raw_input().split()[1:], cmp = lambda a,b: cmp(a+b, b+a)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment