Skip to content

Commit

Permalink
Merge pull request #2 from dsc-iem/master
Browse files Browse the repository at this point in the history
Sync required
  • Loading branch information
ritwiksingh21 authored Oct 13, 2020
2 parents 83636ad + 0b26e81 commit de4d346
Show file tree
Hide file tree
Showing 37 changed files with 1,765 additions and 11 deletions.
23 changes: 23 additions & 0 deletions Attribute Parser/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Attribute Parser

Problem Link: https://www.hackerrank.com/challenges/attribute-parser/problem

This challenge works with a custom-designed markup language HRML.

In HRML, each element consists of a starting and ending tag, and there are attributes associated with each tag.

Only starting tags can have attributes. We can call an attribute by referencing the tag, followed by a tilde, '~' and the name of the attribute.

The tags may also be nested.The opening tags follow the format:

<tag-name attribute1-name = "value1" attribute2-name = "value2" ...>

The attributes are referenced as:

tag1~value

tag1.tag2~name

Given the source code in HRML format consisting of lines, answer queries. For each query, print the value of the attribute specified.

Print "Not Found!" if the attribute does not exist.
58 changes: 58 additions & 0 deletions Attribute Parser/Solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <iostream>
#include <map>
using namespace std;

map <string, string> tagMap;

void createMap(int &n, string pretag) {
if(!n) return;

string line, tag, attr, value;
getline(cin, line);

int i=1;
if(line[i]=='/') { // found closing tag
while(line[i]!='>') i++;
if(pretag.size()>(i-2)) // update tag
tag = pretag.substr(0,pretag.size()-i+1);
else
tag = "";
}
else { // found opening tag
while(line[i]!=' ' && line[i]!='>') i++;
tag = line.substr(1,i-1); // update tag
if(pretag!="") tag = pretag + "." + tag;

int j;
while(line[i]!='>') { // go through attributes
j = ++i;
while(line[i]!=' ') i++;
attr = line.substr(j,i-j); // attribute name

while(line[i]!='\"') i++;
j = ++i;
while(line[i]!='\"') i++;
value = line.substr(j,i-j); // attribute value
i+= 1;

tagMap[tag + "~" + attr] = value;
}
}
createMap(--n, tag);
}

int main() {
int n, q;
cin >> n >> q;
cin.ignore();
createMap(n,"");

string attr, value;
while(q--) {
getline(cin,attr);
value = tagMap[attr];
if(value=="") value = "Not Found!";
cout << value << endl;
}
return 0;
}
57 changes: 57 additions & 0 deletions Bad Triangle/Bad Triangle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <bits/stdc++.h>



using namespace std;

/************************Pre processors & typedefs************************/

#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()

//loop
#define rep(n) for (ll i = 0; i < n; i++)

// datatypes
typedef long long ll;


signed main()
{

ll t;
cin>>t;
while(t--){

ll n;
cin>>n;
ll a[n];
rep(n)
cin>>a[i];
ll f=0;
for(ll i=2;i<n;i++)
{
if((a[0]+a[1])<=a[i])
{

f=i;
break;
}
}
if(f)
cout<<1<<" "<<2<<" "<<f+1<<endl;
else
cout<<"-1"<<endl;
}

return 0;
}





28 changes: 28 additions & 0 deletions Chef and Recipe/Ayush/chefAndRecipe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
t=int(input())
for k in range(t):
n=int(input())
l=list(map(int,input().split()))[:n]
i=0
c=0
done=[]
done1=[]
while(i<n):
if l[i] in done:
print("NO")
c=1
break
else:
srv=l[i]
done.append(srv)
coun=0
while(i<n and l[i]==srv):
i+=1
coun+=1
if coun in done1:
print("NO")
c=1
break
else:
done1.append(coun)
if c==0:
print("YES")
69 changes: 69 additions & 0 deletions Chef and Recipe/Diksha Dixit/ChefRecipeSolution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package codechef;

import java.util.Arrays;
import java.util.Scanner;

public class ChefRecipeSolution {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while (T-- > 0) {
int N = sc.nextInt();
int[] A = new int[N];
int[] B = new int[N];
int[] C = new int[N];
int i = 0;
for (int s = 0; s < N; s++) {
A[s] = sc.nextInt();
}
int k = 1, t = 0;
for (i = 1; i < N; i++) {
if (A[i] == A[i - 1])
k++;
else {
B[t] = A[i - 1];
C[t] = k;
t++;
k = 1;
}
}
B[t] = A[i - 1];
C[t] = k;
t++;

Arrays.sort(B);
Arrays.sort(C);

int y = 0, g = 0;
for (int m = N - 1; m >= 1; m--) {
if (B[m] != 0 && B[m - 1] != 0) {
if (B[m] == B[m - 1]) {
y = 1;
break;
}
}
}

if (y == 1) {
System.out.println("NO");
} else {
for (int m = N - 1; m >= 1; m--) {
if (C[m] != 0 && C[m - 1] != 0) {
if (C[m] == C[m - 1]) {
g = 1;
break;
}
}
}
if (g == 1)
System.out.println("NO");
else
System.out.println("YES");
}
}
sc.close();
}

}
50 changes: 50 additions & 0 deletions Chef and Recipe/Rahul Kashyap/ChefAndRecipeSolution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class ChefAndRecipeSolution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

int T = sc.nextInt();
for (int tc = 0; tc < T; ++tc) {
int N = sc.nextInt();
int[] A = new int[N];
for (int i = 0; i < A.length; ++i) {
A[i] = sc.nextInt();
}

System.out.println(solve(A) ? "YES" : "NO");
}

sc.close();
}

static boolean solve(int[] A) {
Set<Integer> values = new HashSet<>();
Set<Integer> counts = new HashSet<>();
int value = -1;
int count = -1;
for (int i = 0; i <= A.length; ++i) {
if (i != A.length && A[i] == value) {
++count;
} else {
if (value != -1) {
if (values.contains(value) || counts.contains(count)) {
return false;
}

values.add(value);
counts.add(count);
}

if (i != A.length) {
value = A[i];
count = 1;
}
}
}

return true;
}
}
78 changes: 78 additions & 0 deletions Chef and Recipe/chefAndRecipe.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include <bits/stdc++.h>
using namespace std;

int main()
{
int t;
cin >> t;

while (t--)
{
int n;
cin >> n;

int a[n];
for (int i=0; i<n; i++)
cin >> a[i];

map <int, int> m, c;
int curr=a[0], count=1, flag=0;
for (int i=1; i<n; i++)
{
if (a[i] == curr)
{
count++;

if (i == n-1)
{
if (c.find(count) != c.end())
{
flag = 1;
cout << "NO" << endl;
break;
}
}
}

else if (c.find(count) != c.end())
{
flag = 1;
cout << "NO" << endl;
break;
}

else
{
m[curr] = count;
c[count] = 1;

if (m.find(a[i]) != m.end())
{
flag = 1;
cout << "NO" << endl;
break;
}

else
{
count = 1;
curr = a[i];

if (i == n-1)
{
if (c.find(count) != c.end())
{
flag = 1;
cout << "NO" << endl;
break;
}
}
continue;
}
}
}

if (flag == 0)
cout << "YES" << endl;
}
}
Loading

0 comments on commit de4d346

Please sign in to comment.