Skip to content
This repository has been archived by the owner on Oct 19, 2020. It is now read-only.

Anagram #16

Open
wants to merge 3 commits into
base: competitive
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions CodeChef Cookoff october/D-or.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
ll t;
cin>>t;
while(t--)
{
ll a,b;
cin>>a>>b;
ll p = 1;
while(p<b)
{
p*=2;
}
p/=2;
if(p-1>a)
{
cout<<(b|(p-1))<<endl;
}
else
{
ll p[64]={0},q[64]={0};
ll c[64] = {0};
swap(b,a);
ll r = a,w = b;
ll i = 0;
while(i<=63)
{
if(a%2==0)
{
p[i] = 0;
}
else
{
p[i] = 1;
}
a/=2;
i++;
}
i = 0;
while(i<=63)
{
if(b%2==0)
{
q[i] = 0;
}
else
{
q[i] = 1;
}
b/=2;
i++;
}
ll flag = 0;
for(int i = 63 ; i >= 0; i--)
{
if(p[i]==q[i])
{
c[i] = p[i];
continue;
}
else
{
for(int j = i ; j >=0 ; j--)
{
if(p[j]==1)
{
for(int k = j ; k>=0 ; k--)
{
c[k] = 1;
}
break;
}
else
{
c[j] = 0;
}
}
break;
}
}
ll ans = 0;
for(int i = 63 ; i >= 0 ; i--)
{
ans = ans*2+c[i];
}
cout<<ans<<endl;
}
}
}
44 changes: 44 additions & 0 deletions CodeChef Cookoff october/cakewalk.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
set<ll>s;
void precompute()
{
for(auto it = s.begin(); it != s.end() ; it++)
{
if((*it)*10>(ll)1e18)
{
continue;
}
else
{
s.insert((*it)*10);
}

if((*it)*20>(ll)1e18)
{
continue;
}
else
{
s.insert((*it)*20);
}
}
}
int main(){
s.insert(1);
precompute();
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
if(s.find(n)==s.end()){
cout<<"No"<<endl;
}
else{
cout<<"Yes"<<endl;
}
}
}
43 changes: 43 additions & 0 deletions CodeChef Cookoff october/mdedel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
ll a[n];
for(int i = 0 ; i< n ; i++)
{
cin>>a[i];
}
ll indx,indy;
indx = 0;
indy = 0;
ll max = a[0],min = a[0];
for(int i = 0 ;i < n ; i++)
{
if(a[i]>max)
{
max = a[i];
indx = i;
}
if(a[i]<min)
{
min = a[i];
indy = i;
}
}
if(indx>indy)
{
cout<<a[indy]<<" "<<a[indx];
}
else
{
cout<<a[indx]<<" "<<a[indy];
}
cout<<endl;
}
}
37 changes: 37 additions & 0 deletions GFG_JAVA/anagram.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import java.util.*;

public class anagram {

public static void main(String[] args) {
String a = "silenp";
String b = "liste";
boolean isAnagram = false;
boolean visited[] = new boolean[b.length()];
if (a.length() == b.length()) {

for (int i = 0; i < a.length(); i++) {
char c = a.charAt(i);
isAnagram = false;
for (int j = 0; j < b.length(); j++) {
if (b.charAt(j) == c && !visited[j]) {
visited[j] = true;
isAnagram = true;
break;
}
}
if (!isAnagram) {
break;
}

}
}

else {
if (isAnagram) {
System.out.print("Anagram");
} else
System.out.print("Not a Anagram");
}
}

}
29 changes: 29 additions & 0 deletions GFG_JAVA/palindrome.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

package strings;

public class anagram {

public static void main(String[] args) {
String a = "silenp";
String b = "liste";
boolean isAnagram = false;
boolean visited[] = new boolean[b.length()];
if(a.length() == b.length()) {

for(int i = 0;i<a.length();i++) {
char c = a.charAt(i);
isAnagram = false;
for(int j = 0;j<b.length();j++) {
if(b.charAt(j) == c && !visited[j]) {
visited[j] = true;
isAnagram = true;
break;
}
}
if(!isAnagram) {
break;
}


}
}