Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. Alice and Bob each created one problem for HackerRank. A reviewer rates the two challenges, awarding points on a scale from to for three categories: problem clarity, originality, and difficulty.
  2.  
  3. We define the rating for Alice's challenge to be the triplet , and the rating for Bob's challenge to be the triplet .
  4.  
  5. Your task is to find their comparison points by comparing with , with , and with .
  6.  
  7. If , then Alice is awarded point.
  8. If , then Bob is awarded point.
  9. If , then neither person receives a point.
  10. Comparison points is the total points a person earned.
  11.  
  12. Given and , can you compare the two challenges and print their respective comparison points?
  13.  
  14. Input Format
  15.  
  16. The first line contains space-separated integers, , , and , describing the respective values in triplet .
  17. The second line contains space-separated integers, , , and , describing the respective values in triplet .
  18.  
  19. Constraints
  20.  
  21. Output Format
  22.  
  23. Print two space-separated integers denoting the respective comparison points earned by Alice and Bob.
  24.  
  25. Sample Input
  26.  
  27. 5 6 7
  28. 3 6 10
  29. Sample Output
  30.  
  31. 1 1
  32. Explanation
  33.  
  34. In this example:
  35.  
  36. Now, let's compare each individual score:
  37.  
  38. , so Alice receives point.
  39. , so nobody receives a point.
  40. , so Bob receives point.
  41. Alice's comparison score is , and Bob's comparison score is . Thus, we print 1 1 (Alice's comparison score followed by Bob's comparison score) on a single line.
  42.  
  43. initial 'given':
  44.  
  45. using System;
  46. using System.Collections.Generic;
  47. using System.IO;
  48. using System.Linq;
  49. class Solution
  50. {
  51.  
  52. static int[] Solve(int a0, int a1, int a2, int b0, int b1, int b2)
  53. {
  54.  
  55. }
  56.  
  57.  
  58. static void Main(String[] args)
  59. {
  60. string[] tokens_a0 = Console.ReadLine().Split(' ');
  61. int a0 = Convert.ToInt32(tokens_a0[0]);
  62. int a1 = Convert.ToInt32(tokens_a0[1]);
  63. int a2 = Convert.ToInt32(tokens_a0[2]);
  64. string[] tokens_b0 = Console.ReadLine().Split(' ');
  65. int b0 = Convert.ToInt32(tokens_b0[0]);
  66. int b1 = Convert.ToInt32(tokens_b0[1]);
  67. int b2 = Convert.ToInt32(tokens_b0[2]);
  68. int[] result = Solve(a0, a1, a2, b0, b1, b2);
  69. Console.WriteLine(String.Join(" ", result));
  70.  
  71.  
  72. }
  73. }
  74.  
  75. the 'editorial submissions' all seem to assume that 'Solve' is an int, though, not an array, it seems?
  76.  
  77. C
  78. #include<stdio.h>
  79.  
  80. int a_triplet[3], b_triplet[3];
  81. int alice_points = 0;
  82. int bob_points = 0;
  83.  
  84. int main() {
  85. for (int i = 0; i < 3; i++) {
  86. scanf("%d", &a_triplet[i]);
  87. }
  88. for (int i = 0; i < 3; i++) {
  89. scanf("%d", &b_triplet[i]);
  90. }
  91. for(int i = 0; i < 3; i++) {
  92. if (a_triplet[i] > b_triplet[i]) alice_points++;
  93. if (a_triplet[i] < b_triplet[i]) bob_points++;
  94. }
  95. printf("%d %d\n", alice_points, bob_points);
  96. return 0;
  97. }
  98. C++
  99. #include <bits/stdc++.h>
  100. using namespace std;
  101.  
  102. int main(){
  103. vector <int> a_triplet(3);
  104. vector <int> b_triplet(3);
  105. int alice_points = 0;
  106. int bob_points = 0;
  107.  
  108. for (int i = 0; i < 3; i++) {
  109. cin >> a_triplet[i];
  110. }
  111. for (int i = 0; i < 3; i++) {
  112. cin >> b_triplet[i];
  113. }
  114.  
  115. for(int i = 0; i < 3; i++) {
  116. if (a_triplet[i] > b_triplet[i]) alice_points++;
  117. if (a_triplet[i] < b_triplet[i]) bob_points++;
  118. }
  119. cout << alice_points << " " << bob_points << endl;
  120. return 0;
  121. }
  122. Python 2
  123. a_triplet = map(int, raw_input().split())
  124. b_triplet = map(int, raw_input().split())
  125. alice_points = 0
  126. bob_points = 0
  127. for a_val, b_val in zip(a_triplet, b_triplet):
  128. if a_val < b_val:
  129. bob_points += 1
  130. elif a_val > b_val:
  131. alice_points += 1
  132. print alice_points, bob_points
  133. Python 3
  134. a_triplet = map(int, input().split())
  135. b_triplet = map(int, input().split())
  136. alice_points = 0
  137. bob_points = 0
  138. for a_val, b_val in zip(a_triplet, b_triplet):
  139. if a_val < b_val:
  140. bob_points += 1
  141. elif a_val > b_val:
  142. alice_points += 1
  143. print(alice_points, bob_points)
  144. Ruby
  145. a_triplet = gets.strip.split(' ').map(&:to_i)
  146. b_triplet = gets.strip.split(' ').map(&:to_i)
  147.  
  148. alice_points = 0
  149. bob_points = 0
  150.  
  151. a_triplet.zip(b_triplet).each do |a_val, b_val|
  152. if a_val > b_val
  153. alice_points += 1
  154. elsif a_val < b_val
  155. bob_points += 1
  156. end
  157. end
  158.  
  159. puts "#{alice_points} #{bob_points}"
  160. Java
  161. import java.io.*;
  162. import java.util.*;
  163. import java.text.*;
  164. import java.math.*;
  165. import java.util.regex.*;
  166.  
  167. public class Solution {
  168. public static void main(String[] args) {
  169. Scanner in = new Scanner(System.in);
  170. int[] a_triplet = new int[3];
  171. int[] b_triplet = new int[3];
  172. for (int i = 0; i < 3; i++) {
  173. a_triplet[i] = in.nextInt();
  174. }
  175. for (int i = 0; i < 3; i++) {
  176. b_triplet[i] = in.nextInt();
  177. }
  178. int alice_points = 0;
  179. int bob_points = 0;
  180. for (int i = 0; i < 3; i++) {
  181. if (a_triplet[i] > b_triplet[i]) {
  182. alice_points += 1;
  183. } else if (a_triplet[i] < b_triplet[i]) {
  184. bob_points += 1;
  185. }
  186. }
  187. System.out.printf("%d %d", alice_points, bob_points);
  188. }
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement