-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ows-ali/master
Update repository
- Loading branch information
Showing
13 changed files
with
346 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import java.io.*; | ||
class FLOW009 { | ||
public static void main(String args[]) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
PrintWriter out = new PrintWriter(System.out, true); | ||
|
||
int t = Integer.parseInt(br.readLine().trim()); | ||
|
||
while (t-- > 0) { | ||
String[] tok = br.readLine().split(" "); | ||
|
||
double quan = Double.parseDouble(tok[0]); | ||
double price = Double.parseDouble(tok[1]); | ||
|
||
double cost = quan * price; | ||
if (quan > 1000) cost -= ((quan * price) / 100 * 10); | ||
|
||
out.printf("%.6f\n", cost); | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
void readInt(int &n) { | ||
static char c; | ||
while ((c = getchar_unlocked()) && c <= ' '); | ||
n = c - '0'; | ||
|
||
while ((c = getchar_unlocked()) && c > ' ') n = (n << 3) + (n << 1) + c - '0'; | ||
} | ||
|
||
int main() { | ||
int n, k; | ||
readInt(n); readInt(k); | ||
|
||
int ans = 0; | ||
while (n--) { | ||
int foo; readInt(foo); | ||
ans += foo % k == 0; | ||
} | ||
|
||
printf("%d\n", ans); | ||
return 0; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
class Laddu { | ||
public static void main(String args[]) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
PrintWriter out = new PrintWriter(System.out, true); | ||
|
||
int t = Integer.parseInt(br.readLine()); | ||
while (t-- > 0) { | ||
StringTokenizer st = new StringTokenizer(br.readLine(), " "); | ||
|
||
int numAct = Integer.parseInt(st.nextToken()); | ||
int national = 0; | ||
|
||
if (st.nextToken().equals("INDIAN")) national = 1; | ||
|
||
int score = 0; | ||
while (numAct-- > 0) { | ||
score += laddus(br.readLine()); | ||
} | ||
|
||
int perMonth = national == 0 ? 400 : 200; | ||
out.println((score - (score % perMonth)) / perMonth); | ||
} | ||
|
||
out.close(); | ||
} | ||
public static int laddus(String str) { | ||
String[] arr = str.split(" "); | ||
|
||
if (arr.length == 1) { | ||
switch (arr[0]) { | ||
case "TOP_CONTRIBUTOR" : | ||
return 300; | ||
case "CONTEST_HOSTED" : | ||
return 50; | ||
default : | ||
return 0; | ||
} | ||
} else { | ||
switch (arr[0]) { | ||
case "BUG_FOUND" : | ||
return Integer.parseInt(arr[1]); | ||
case "CONTEST_WON" : | ||
if (Integer.parseInt(arr[1]) <= 20) { | ||
return 300 + 20 - Integer.parseInt(arr[1]); | ||
} else return 300; | ||
default : | ||
return 0; | ||
} | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <iostream> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
int t; | ||
scanf("%d", &t); | ||
|
||
while (t-- > 0) { | ||
int n, k; | ||
scanf("%d %d", &n, &k); | ||
|
||
int arr[n]; | ||
int totalSum = 0; | ||
for (int i = 0; i < n; i++) { | ||
cin >> arr[i]; | ||
|
||
totalSum += arr[i]; | ||
} | ||
|
||
sort(arr, arr + n); | ||
|
||
if (k > n / 2) | ||
k = n - k; | ||
int sumSon = 0, sumFather = 0; | ||
for (int i = 0; i < k; i++) | ||
sumSon += arr[i]; | ||
|
||
sumFather = totalSum - sumSon; | ||
|
||
int diff = sumFather - sumSon; | ||
|
||
printf("%d\n", diff); | ||
} | ||
|
||
return 0; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
int t; | ||
cin >> t; | ||
|
||
while (t-- > 0) { | ||
long n, k; | ||
cin >> n >> k; | ||
|
||
if (k == 0) | ||
cout << "0 " << n << endl; | ||
else | ||
cout << n / k << " " << n % k << endl; | ||
} | ||
return 0; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import java.util.Scanner; | ||
|
||
public class SumTrain { | ||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
|
||
int notc = scanner.nextInt(); | ||
int nol; | ||
short[][] arr; | ||
for (int i = 0; i < notc; i++) { | ||
|
||
nol = scanner.nextInt(); | ||
arr = new short[nol][nol]; | ||
for (int j = 0; j < nol; j++) | ||
for (int k = 0; k <= j; k++) | ||
arr[j][k] = scanner.nextByte(); | ||
|
||
for (int j = 1; j < nol; j++) | ||
for (int k = 0; k <= j; k++) | ||
if (k == 0) | ||
arr[j][k] += arr[j - 1][k]; | ||
else if (j == k) | ||
arr[j][k] += arr[j - 1][k - 1]; | ||
else | ||
arr[j][k] += max(arr[j - 1][k], arr[j - 1][k - 1]); | ||
|
||
long maxNum = arr[nol - 1][0]; | ||
for (int j = 1; j < nol; j++) | ||
if (maxNum < arr[nol - 1][j]) | ||
maxNum = arr[nol - 1][j]; | ||
System.out.println(maxNum); | ||
} | ||
} | ||
|
||
public static short max(short a, short b) { | ||
|
||
return a > b ? a : b; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <cstdio> | ||
#include <iostream> | ||
#include <map> | ||
#include <iterator> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
map <int, int> m; | ||
|
||
int a, b, c; | ||
scanf("%d %d %d", &a, &b, &c); | ||
|
||
int temp; | ||
for (int i = 0; i < a + b + c; i++) { | ||
scanf("%d", &temp); | ||
m.insert(pair<int, int>(temp, m[temp]++)); | ||
} | ||
|
||
map <int, int> :: iterator itr; | ||
int counter = 0; | ||
for (itr = m.begin(); itr != m.end(); ++itr) { | ||
if (itr->second >= 2) | ||
counter++; | ||
} | ||
|
||
printf("%d\n", counter); | ||
for (itr = m.begin(); itr != m.end(); ++itr) { | ||
if (itr->second >= 2) | ||
printf("%d\n", itr->first); | ||
} | ||
|
||
return 0; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
int n, k; | ||
scanf("%d %d", &n, &k); | ||
|
||
int arr[n]; | ||
for (int i = 0; i < n; i++) | ||
cin >> arr[i]; | ||
|
||
for (int j = k; j < n; j++) | ||
cout << arr[j] << " "; | ||
|
||
for (int p = 0; p < k; p++) | ||
cout << arr[p] << " "; | ||
|
||
return 0; | ||
} |
22 changes: 22 additions & 0 deletions
22
Hackerrank/detect-whether-a-linked-list-contains-a-cycle.cpp
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#https://www.hackerrank.com/challenges/detect-whether-a-linked-list-contains-a-cycle/problem | ||
|
||
bool has_cycle(Node* head) { | ||
|
||
if (head == NULL || head->next == NULL){ | ||
return false; | ||
} | ||
else{ | ||
Node *runner = head->next->next; | ||
|
||
while (runner != NULL && runner != head){ | ||
runner = runner->next->next; | ||
head = head->next; | ||
} | ||
if (runner == NULL){ | ||
return false; | ||
} | ||
else{ | ||
return true; | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import java.io.*; | ||
import java.math.*; | ||
import java.security.*; | ||
import java.text.*; | ||
import java.util.*; | ||
import java.util.concurrent.*; | ||
import java.util.regex.*; | ||
public class Solution { | ||
// Complete the staircase function below. | ||
static void staircase(int n) { | ||
int m=n; | ||
|
||
while(n!=0){ | ||
n--; | ||
for(int i=0;i<n;i++) System.out.print(" "); | ||
for(int i=0;i<m-n;i++) System.out.print("#"); | ||
System.out.println(); | ||
} | ||
} | ||
private static final Scanner scanner = new Scanner(System.in); | ||
public static void main(String[] args) { | ||
int n = scanner.nextInt(); | ||
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); | ||
staircase(n); | ||
scanner.close(); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.