diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 6b19b25..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/0-1 Knapsack Problem/Question.txt b/0-1 Knapsack Problem/Question.txt deleted file mode 100644 index e2d9143..0000000 --- a/0-1 Knapsack Problem/Question.txt +++ /dev/null @@ -1,3 +0,0 @@ -Given weights and values of n items, put these items in a knapsack of capacity W to get the maximum total value in the knapsack. In other words, given two integer arrays val[0..n-1] and wt[0..n-1] which represent values and weights associated with n items respectively. Also given an integer W which represents knapsack capacity, find out the maximum value subset of val[] such that sum of the weights of this subset is smaller than or equal to W. You cannot break an item, either pick the complete item, or don’t pick it (0-1 property). - - diff --git a/0-1 Knapsack Problem/Solution.c b/0-1 Knapsack Problem/Solution.c deleted file mode 100644 index 76a2d73..0000000 --- a/0-1 Knapsack Problem/Solution.c +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include - -int max(int a, int b) -{ - if (a>b) - return a; - else - return b; -} - -int main() -{ - int n, value[100], capacity, weight[100],i,j,K[100][100]; - printf("Input number of items:"); - scanf("%d",&n); - printf("Enter values:"); - for(i=0;i - -using namespace std; - -int main() - -{ - -int N,i=0; - -cin>>N; - -while(i> abbreviate("Portable Network Graphics") -# => "PNG" -# >> abbreviate("Ruby on Rails") -# => "ROR" -# >> abbreviate("GNU Image Manipulation Program") -# => "GIMP" diff --git a/Aggressive Cows Spoj/problem statement.txt b/Aggressive Cows Spoj/problem statement.txt deleted file mode 100644 index c064deb..0000000 --- a/Aggressive Cows Spoj/problem statement.txt +++ /dev/null @@ -1,34 +0,0 @@ -AGGRCOW - Aggressive cows -#binary-search - -Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The stalls are located along a straight line at positions x1,...,xN (0 <= xi <= 1,000,000,000). - -His C (2 <= C <= N) cows don't like this barn layout and become aggressive towards each other once put into a stall. To prevent the cows from hurting each other, FJ wants to assign the cows to the stalls, such that the minimum distance between any two of them is as large as possible. What is the largest minimum distance? -Input - -t the number of test cases, then t test cases follows. -* Line 1: Two space-separated integers: N and C -* Lines 2..N+1: Line i+1 contains an integer stall location, xi -Output - -For each test case output one integer: the largest minimum distance. -Example - -Input: - -1 -5 3 -1 -2 -8 -4 -9 - -Output: - -3 - -Output details: - -FJ can put his 3 cows in the stalls at positions 1, 4 and 8, -resulting in a minimum distance of 3. \ No newline at end of file diff --git a/Aggressive Cows Spoj/solution1.cpp b/Aggressive Cows Spoj/solution1.cpp deleted file mode 100644 index 2556e23..0000000 --- a/Aggressive Cows Spoj/solution1.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include -using namespace std; - -int main(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - long long t,n,c; - cin>>t; - vector ans; - - while(t--){ - cin>>n>>c; - long long x[n]; - long long mind=LLONG_MAX; - for(long long i=0;i>x[i]; - mind=min(x[i],mind); - } - sort(x,x+n); - - long long low=mind; - long long high=x[n-1]-x[0]; - long long mid; - - while(low < high){ - mid = low+(high-low+1)/2; - long long cows=1; - long long idx=0; - for(long long i=1;i= mid) {cows++; idx=i;} - } - if(cows >= c) low=mid; - else high=mid-1; - } - ans.push_back(low); - } - - for(vector::iterator it=ans.begin();it!=ans.end();it++){ - cout<<*it< -using namespace std; - -int main(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - long long t,n,c; - cin>>t; - vector ans; - while(t--){ - cin>>n>>c; - long long x[n]; - long long mind=LLONG_MAX; - for(long long i=0;i>x[i]; - mind=min(x[i],mind); - } - sort(x,x+n); - - long long low=mind; - long long high=x[n-1]-x[0]; - long long mid; - long long maxd=-1; - - while(low < high){ - mid = low+(high-low)/2; - long long cows=1; - long long idx=0; - for(long long i=1;i= mid) {cows++; idx=i;} - } - if(cows >= c) {low=mid+1; maxd=max(maxd,mid);} - else high=mid; - } - ans.push_back(maxd); - } - - for(vector::iterator it=ans.begin();it!=ans.end();it++){ - cout<<*it< {}'.format(s1, s2, are_anagram(s1, s2))) - print('{} / {} -> {}'.format(s1, s3, are_anagram(s1, s3))) - print('{} / {} -> {}'.format(s2, s3, are_anagram(s2, s3))) - -if __name__=='__main__': - main() diff --git a/AnagramChecking/anagram_checking.txt b/AnagramChecking/anagram_checking.txt deleted file mode 100644 index 43158e6..0000000 --- a/AnagramChecking/anagram_checking.txt +++ /dev/null @@ -1,3 +0,0 @@ -Anagram checking - -Write a function that check whether two given strings are anagram of each other. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase using all the original letters exactly once. An optimized solution should have a O(n) time complexity and O(1) space complexity. diff --git a/Armstrong No/armstrongnum.c b/Armstrong No/armstrongnum.c deleted file mode 100644 index e77b25d..0000000 --- a/Armstrong No/armstrongnum.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include - - int main() - { - int i, temp,num,count=0,sum=0; - - scanf("%d",&num); - - temp=num; - while(temp!=0) - { - count++; - temp=temp/10; - } - temp=num; - while(temp!=0) - { - sum=sum + pow(temp%10,count); - temp=temp/10; - } - printf("%d",sum); - - //and if sum is equal to num then that no is said to be Armstrong number.TRy 371 - return 0; - } diff --git a/Arrangement_of_Queue/Question.txt b/Arrangement_of_Queue/Question.txt deleted file mode 100644 index 7783a11..0000000 --- a/Arrangement_of_Queue/Question.txt +++ /dev/null @@ -1,4 +0,0 @@ -Find the arrangement of queue at given time: - -n people are standing in a queue to buy entry ticket for the carnival. People present there strongly believe in chivalry. Therefore, at time = t, if a man at position x, finds a woman standing behind him then he exchanges his position with her and therefore, at time = t+1, woman is standing at position x while man is standing behind her. -Given the total number of people standing in a queue as n, particular instant of time as t and the initial arrangement of the queue in the form of a string containing M representing man at position i and W representing woman is at position i, find out the arrangement of the queue at time = t. \ No newline at end of file diff --git a/Arrangement_of_Queue/README.md b/Arrangement_of_Queue/README.md deleted file mode 100644 index d4e8505..0000000 --- a/Arrangement_of_Queue/README.md +++ /dev/null @@ -1,2 +0,0 @@ -### One of the easy Competitve Programming Problems -but still a great add diff --git a/Arrangement_of_Queue/Solution.py b/Arrangement_of_Queue/Solution.py deleted file mode 100644 index bb8a7a4..0000000 --- a/Arrangement_of_Queue/Solution.py +++ /dev/null @@ -1,24 +0,0 @@ - -def solve(n, t, p) : - - s = list(p) - - for i in range(0, t) : - - for j in range(0, n - 1) : - - if (s[j] == 'B' and - s[j + 1] == 'G') : - - temp = s[j]; - s[j] = s[j + 1]; - s[j + 1] = temp; - j = j + 1 - - print (''.join(s)) - - -n = 6 -t = 2 -p = "BBGBBG" -solve(n, t, p) diff --git a/Average/Average-Question.txt b/Average/Average-Question.txt deleted file mode 100644 index 2087165..0000000 --- a/Average/Average-Question.txt +++ /dev/null @@ -1,81 +0,0 @@ -Problem Name: Average - -You are given a sequence of integers a1, a2, ..., aN. An element ak is said to be an average element if there are indices i, j (with i ≠ j) such that ak = (ai + aj) / 2. - -In the sequence - -3 7 10 22 17 15 - -for i=1, j=5 and k=3, we get ak = (ai + aj)/2. Thus a3 = 10 is an average element in this sequence. You can check that a3 is the only average element in this sequence. - -Consider the sequence - -3 7 10 3 18 - -With i=1, j=4 and k=1 we get ak = (ai +aj)/2. Thus a1=3 is an average element. We could also choose i=1, j=4 and k=4 and get ak=(ai +aj)/2. You can check that a1 and a4 are the only average elements of this sequence. - -On the other hand, the sequence - -3 8 11 17 30 - -has no average elements. - -Your task is to count the number of average elements in the given sequence. - -Input format - -The first line contains a single integer N indicating the number of elements in the sequence. This is followed by N lines containing one integer each (Line i+1 contains ai). (You may assume that ai + aj would not exceed MAXINT for any i and j). - -Output format - -The output must consist of a single line containing a single integer k indicating the number of average elements in the given sequence. - -Test Data: - -You may assume that N ≤ 10000. Further, you may assume that in 30% of the inputs N ≤ 200 and that in 60% of the inputs N ≤ 5000. - -Example: - -We illustrate the input and output format using the above examples: - -Sample Input 1: - -6 -3 -7 -10 -17 -22 -15 - -Sample Output 1: - -1 - -Sample Input 2: - -5 -3 -7 -10 -3 -18 - -Sample Output 2: - -2 - -Sample Input 3; - -5 -3 -8 -11 -17 -30 - -Sample Output 3: - -0 -PROBLEM 2 avgBasics -Create a program to calculate the average of some integers taken input from user. diff --git a/Average/Solution.cpp b/Average/Solution.cpp deleted file mode 100644 index eb8767c..0000000 --- a/Average/Solution.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include -int arr[100000]; -using namespace std; -int main() -{ - int n; - cin>>n; - for(int h=0;h>arr[h]; - sort(arr,arr+n); - int count=0; - for(int i=0;i=0 && h - -using namespace std; -int main() -{int x; -float total=0; -int num=0; - - -while (num<5){ - cin>>x; - total=total+x; - num=num+1; -} -float avgBasic= total/num; -cout< -using namespace std; -map dp; -long long optcoins(int n){ - if(n<12) - return n; - if(dp.count(n)) - return dp[n]; - dp[n]=optcoins(n/2)+optcoins(n/3)+optcoins(n/4); - return dp[n]; -} -int main(){ - int x; - while(scanf("%d",&x)!=EOF) - printf("%lld\n",optcoins(x)); - return 0; -} diff --git a/COINS/Question.txt b/COINS/Question.txt deleted file mode 100644 index 4e5531f..0000000 --- a/COINS/Question.txt +++ /dev/null @@ -1,24 +0,0 @@ -In Byteland they have a very strange monetary system. - -Each Bytelandian gold coin has an integer number written on it. A coin n can be exchanged in a bank into three coins: n/2, n/3 and n/4. But these numbers are all rounded down (the banks have to make a profit). - -You can also sell Bytelandian coins for American dollars. The exchange rate is 1:1. But you can not buy Bytelandian coins. - -You have one gold coin. What is the maximum amount of American dollars you can get for it? - -Input -The input will contain several test cases (not more than 10). Each testcase is a single line with a number n, 0 <= n <= 1 000 000 000. It is the number written on your coin. - -Output -For each test case output a single line, containing the maximum amount of American dollars you can make. - -Example -Input: -12 -2 - -Output: -13 -2 - -You can change 12 into 6, 4 and 3, and then change these into 6+4+3=13. If you try changing the coin 2 into 3 smaller coins, you will get 1, 0 and 0, and later you can get no more than 1outofthem.Itisbetterjusttochangethe2coindirectlyinto2. diff --git a/COINS/Readme.md b/COINS/Readme.md deleted file mode 100644 index a2c7ef8..0000000 --- a/COINS/Readme.md +++ /dev/null @@ -1 +0,0 @@ -One of the first and the easiest question of Dynamic Programming. diff --git a/COINS/Solution.cpp b/COINS/Solution.cpp deleted file mode 100644 index 8ccc760..0000000 --- a/COINS/Solution.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include - -using namespace std; -map dp; - -long long f(int n){ - if(n==0) return 0; - - if(dp[n]!=0) return dp[n]; - - long long aux=f(n/2)+f(n/3)+f(n/4); - - if(aux>n) dp[n]=aux; - else dp[n]=n; - - return dp[n]; -} - -int main(){ - int n; - - while(scanf("%d",&n)==1) printf("%lld\n",f(n)); - - return 0; -} \ No newline at end of file diff --git a/CONTON/QUESTION.txt b/CONTON/QUESTION.txt deleted file mode 100644 index a145486..0000000 --- a/CONTON/QUESTION.txt +++ /dev/null @@ -1,26 +0,0 @@ -One of the famous proofs of modern mathematics is Georg Cantor's demonstration that the set of rational numbers is enumerable. -The proof works by using an explicit enumeration of rational numbers as shown in the diagram below. -1/1 1/2 1/3 1/4 1/5 ... -2/1 2/2 2/3 2/4 -3/1 3/2 3/3 -4/1 4/2 -5/1 -In the above diagram, the first term is 1/1, the second term is 1/2, the third term is 2/1, the fourth term is 3/1, the fifth term is 2/2, and so on. -Input -The input starts with a line containing a single integer t <= 20, the number of test cases. t test cases follow. - -Then, it contains a single number per line. -Output -You are to write a program that will read a list of numbers in the range from 1 to 10^7 and will print for each number the corresponding term in Cantor's enumeration as given below. - -Example -Input: -3 -3 -14 -7 - -Output: -TERM 3 IS 2/1 -TERM 14 IS 2/4 -TERM 7 IS 1/4 \ No newline at end of file diff --git a/CONTON/solution.c b/CONTON/solution.c deleted file mode 100644 index 1f8a831..0000000 --- a/CONTON/solution.c +++ /dev/null @@ -1,84 +0,0 @@ -#include - -using namespace std; - - -int main() -{ - -long long n,a,b,num,den; - - int t; - - cin>>t; - - while(t--) - - { - - cin>>a; - - n=(-1+sqrt(1+(8*a)))/2; - - b=(n*(n+1))/2; - - if(a==b) - - { - - if(a%2==0) - - { - - den=n; - - num=1; - - cout<<"TERM "< -1) { - i = polar[cenit.indexOf(i)]; - encryptWordArray.push(i); - } else if (polar.indexOf(i) > -1) { - i = cenit[polar.indexOf(i)]; - encryptWordArray.push(i); - } else { - encryptWordArray.push(i); - } - }); - return encryptWordArray.join("").toUpperCase(); -} - -console.log(processWord("COMPUTER")); \ No newline at end of file diff --git a/Check_String_Palindrome/Source1.cpp b/Check_String_Palindrome/Source1.cpp deleted file mode 100644 index 0fdda1d..0000000 --- a/Check_String_Palindrome/Source1.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include - -using namespace std; - -bool checkStringPallindrome(string inputString); - -bool checkStringPallindrome(string inputString) { - for (int i = 0; i < (inputString.length() / 2); i++) { - if (inputString.at(i) != inputString.at(inputString.length() - 1 - i)) { - return false; - } - } - return true; -} -int main() { - - string input; - getline(cin, input); - if (checkStringPallindrome(input)) { - cout << "true" << endl; - } - else { - cout << "false" << endl; - } - - system("pause"); - return 1; -} \ No newline at end of file diff --git a/Check_String_Palindrome/problem.txt b/Check_String_Palindrome/problem.txt deleted file mode 100644 index 14448c8..0000000 --- a/Check_String_Palindrome/problem.txt +++ /dev/null @@ -1,17 +0,0 @@ -You are given a string consisting of letters from a-z and A-Z. No any special characters. A palindrome is a word which is equal to itself when reversed. Examples are DAD, MOM, APCPA. Words like TIGER, RAT are not palindromes. -Input and Output: -The function should take a queue of characters as input and return True or False as output. If the queue is empty return true. - - -Sample Input 1: -ABCBA -Sample Output 1: -true -Sample Input 2: -PrOGraMiNG -Sample Output 2: -false -Sample Input 3: -AA -Sample Output 3: -true \ No newline at end of file diff --git a/Chefdil/ans.cpp b/Chefdil/ans.cpp deleted file mode 100644 index c8c9330..0000000 --- a/Chefdil/ans.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -using namespace std; -int main() -{ - int t; - cin>>t; - while(t--) - { - string a; - cin>>a; - int b=0; - for(int i=0;i= 0 && j >= 0; ) { - if (y[j] >= x[i]) { - ans += s1; - s2 -= y[j]; - --j; - } else { - ans += s2; - s1 -= x[i]; - --i; - } - } - out.println(ans); - } - - } - - static class OutputWriter { - private final PrintWriter writer; - - public OutputWriter(OutputStream outputStream) { - writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); - } - - public OutputWriter(Writer writer) { - this.writer = new PrintWriter(writer); - } - - public void close() { - writer.close(); - } - - public void println(int i) { - writer.println(i); - } - - } - - static class InputReader { - private InputStream stream; - private byte[] buf = new byte[1024]; - private int curChar; - private int numChars; - private InputReader.SpaceCharFilter filter; - - public InputReader(InputStream stream) { - this.stream = stream; - } - - public int read() { - if (numChars == -1) { - throw new InputMismatchException(); - } - if (curChar >= numChars) { - curChar = 0; - try { - numChars = stream.read(buf); - } catch (IOException e) { - throw new InputMismatchException(); - } - if (numChars <= 0) { - return -1; - } - } - return buf[curChar++]; - } - - public int nextInt() { - int c = read(); - while (isSpaceChar(c)) { - c = read(); - } - int sgn = 1; - if (c == '-') { - sgn = -1; - c = read(); - } - int res = 0; - do { - if (c < '0' || c > '9') { - throw new InputMismatchException(); - } - res *= 10; - res += c - '0'; - c = read(); - } while (!isSpaceChar(c)); - return res * sgn; - } - - public String nextString() { - int c = read(); - while (isSpaceChar(c)) { - c = read(); - } - StringBuilder res = new StringBuilder(); - do { - if (Character.isValidCodePoint(c)) { - res.appendCodePoint(c); - } - c = read(); - } while (!isSpaceChar(c)); - return res.toString(); - } - - public boolean isSpaceChar(int c) { - if (filter != null) { - return filter.isSpaceChar(c); - } - return isWhitespace(c); - } - - public static boolean isWhitespace(int c) { - return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; - } - - public String next() { - return nextString(); - } - - public int[] nextIntArray(int n) { - int[] array = new int[n]; - for (int i = 0; i < n; ++i) array[i] = nextInt(); - return array; - } - - public interface SpaceCharFilter { - public boolean isSpaceChar(int ch); - - } - - } -} - diff --git a/Counting-Change-Combinations/counting.txt b/Counting-Change-Combinations/counting.txt deleted file mode 100644 index e7aba7c..0000000 --- a/Counting-Change-Combinations/counting.txt +++ /dev/null @@ -1,13 +0,0 @@ -Write a function that counts how many different ways you can make change for an amount of money, given an array of coin denominations. For example, there are 3 ways to give change for 4 if you have coins with denomination 1 and 2: - -1+1+1+1, 1+1+2, 2+2. -The order of coins does not matter: - -1+1+2 == 2+1+1 -Also, assume that you have an infinite amount of coins. - -Your function should take an amount to change and an array of unique denominations for the coins: - - countChange(4, [1,2]) // => 3 - countChange(10, [5,2,3]) // => 4 - countChange(11, [5,7]) // => 0 \ No newline at end of file diff --git a/Counting-Change-Combinations/solution.js b/Counting-Change-Combinations/solution.js deleted file mode 100644 index fcb7e85..0000000 --- a/Counting-Change-Combinations/solution.js +++ /dev/null @@ -1,24 +0,0 @@ -let countChange = function(money, coins) { - if (coins.length === 0) { - return 0; - } - - coins = coins.slice(0).sort(); - let result = 0, - largestCoin = coins.pop(), - maxCount = 0; - let maxRemain = money % largestCoin; - - if (maxRemain === 0) { - result++; - maxCount = money / largestCoin - 1; - } else { - maxCount = (money - maxRemain) / largestCoin; - } - - for (let i = maxCount; i >= 0; i--) { - result += countChange(money - largestCoin * i, coins); - } - - return result; -} \ No newline at end of file diff --git a/DP- Min Steps to 1/Min Steps to 1 Problem Statement.txt b/DP- Min Steps to 1/Min Steps to 1 Problem Statement.txt deleted file mode 100644 index f3a3837..0000000 --- a/DP- Min Steps to 1/Min Steps to 1 Problem Statement.txt +++ /dev/null @@ -1,35 +0,0 @@ -Type: Dynamic Programming - -Code : Min Steps to 1 - -Given a positive integer n, find the minimum number of steps s, that takes n to 1. -You can perform any one of the following 3 steps. -1.) Subtract 1 from it. (n= n - 1) , -2.) If its divisible by 2, divide by 2.( if n%2==0, then n= n/2 ) , -3.) If its divisible by 3, divide by 3. (if n%3 == 0, then n = n / 3 ). - -Input format : -Line 1 : A single integer i.e. n -Output format : -Line 1 : Single integer i.e number of steps -Constraints : -1 <= n <= 500 - -Sample Input 1 : -4 -Sample Output 1 : -2 -Sample Output 1 Explanation : -For n = 4 -Step 1 : n = 4/2 = 2 -Step 2 : n = 2/2 = 1 - -Sample Input 2 : -7 -Sample Output 2 : -3 -Sample Output 2 Explanation : -For n = 7 -Step 1 : n = 7 - 1 = 6 -Step 2 : n = 6 / 3 = 2 -Step 3 : n = 2 / 2 = 1 \ No newline at end of file diff --git a/DP- Min Steps to 1/minsteps.java b/DP- Min Steps to 1/minsteps.java deleted file mode 100644 index 8cb26ab..0000000 --- a/DP- Min Steps to 1/minsteps.java +++ /dev/null @@ -1,47 +0,0 @@ -import java.util.Scanner; -import java.lang.Math; - -public class minsteps -{ - public static Scanner s=new Scanner(System.in); - - public static void main(String[] args) - { - int n = s.nextInt(); - System.out.println(countStepsTo1(n)); - } - - public static int countStepsTo1(int n) - { - if(n<=1) - return 0; - if(n==2 || n==3) - return 1; - int ans[]=new int[n+1]; - - ans[0]=0; - ans[1]=0; - ans[2]=1; - ans[3]=1; - - - - for(int i=4;i -using namespace std; -int main() -{ - char amp[100]; - cin.getline(amp,99,'\n'); - int len=strlen(amp); - - - int arr[10]={0}; - - int count=0,i=0; - int start=0; - for(int l=start;l<=len;l++) - { - - if(amp[l]==' ' || amp[l]=='\0') - { - //cout<<"hi "<=start;m--,n++) - { - arr[i]+= (amp[m]-'0')*pow(10,n); - - } - - if(l==len) - break; - i++; - start=l+1; - } - - } - - sort(arr,arr+count); - int ans=1; - for(int a=count-2;a>=0;a--) - { - if(arr[count-1]%arr[a]!=0) - { - ans=0; - break; - } - } - - cout< map = new HashMap(); - String[] x = new String[raw.length]; - for(int i=0; i50 or process_queue[i][1]<0: - process_queue[i][1]=int(raw_input('Enter p_arrival(Should be between 0-50 sec): ')) - total_wtime += process_queue[i][1] - process_queue[i].append(int(raw_input('Enter p_bust: '))) - while process_queue[i][2]>10 or process_queue[i][2]<0: - process_queue[i][2]=int(raw_input('Enter p_burst(Should be between 0-10 msec): ')) - process_queue[i].append(process_queue[i][1]) - print '' - -process_queue.sort(key = lambda process_queue:process_queue[1]) -exe=process_queue[0][1]+process_queue[0][2]; -for j in xrange(n-1): - i=j+1 - if exe < process_queue[i][1]: - exe=process_queue[i][1]+process_queue[i][2] - else: - process_queue[i][3]=exe - exe=exe+process_queue[i][2] - - -print 'ProcessName\tArrivalTime\tBurstTime\tExecutionStartTime' -for i in xrange(n): - print process_queue[i][0],'\t\t',process_queue[i][1],'\t\t',process_queue[i][2],'\t\t',process_queue[i][3] - -print 'Total waiting time: ',total_wtime -print 'Average waiting time: ',(total_wtime/n) diff --git a/FCFS/question.txt b/FCFS/question.txt deleted file mode 100644 index 49d12bb..0000000 --- a/FCFS/question.txt +++ /dev/null @@ -1,9 +0,0 @@ -Implement the First-Come, First-Serve process scheduling algorithm. - -The input to your algorithm must be a 2-D array that contains values for(Burst Time, Arrival Time) for 10 processes. Initialize random values for each of the 2 attributes for each process and print this table. - -Acceptable range of values for input: -Burst Time: [0,10]microseconds -Arrival Time: [0,50]seconds -*Burst Time is the amount of time the process requires to execute on the CPU. - diff --git a/Factorial using Recursion/Factorial using recursion.cpp b/Factorial using Recursion/Factorial using recursion.cpp deleted file mode 100644 index 3756f5f..0000000 --- a/Factorial using Recursion/Factorial using recursion.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -int c,fac; -int fact(int n) -{ - if(n==0){ - return 1; - } - fac=n*fact(n-1); - return fac; -} -int main() -{ - printf("enter a number "); - scanf("%d",&c); - fact(c); - printf("factorial of entered no. is %d",fac); -return 0; -} diff --git a/Factorial using Recursion/Question.txt b/Factorial using Recursion/Question.txt deleted file mode 100644 index e11ae3b..0000000 --- a/Factorial using Recursion/Question.txt +++ /dev/null @@ -1,15 +0,0 @@ -Find factorial of a number using recursion. - -Input -The input will contain several test cases (not more than 10). Each testcase is a single line with a number n, 0 <= n <= 1 000 000 000. - -Output -For each test case output a single line, containing the factorial as the answer. - -Example -Input: -1 -5 - -Output: -120 \ No newline at end of file diff --git a/Fair Rations/Answer.cpp b/Fair Rations/Answer.cpp deleted file mode 100644 index 9cacb35..0000000 --- a/Fair Rations/Answer.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include - -using namespace std; - -vector split_string(string); - -// Complete the fairRations function below. -int fairRations(vector B) { - int loaf=0; - vector p; - for(int i=0;i> N; - cin.ignore(numeric_limits::max(), '\n'); - - string B_temp_temp; - getline(cin, B_temp_temp); - - vector B_temp = split_string(B_temp_temp); - - vector B(N); - - for (int i = 0; i < N; i++) { - int B_item = stoi(B_temp[i]); - - B[i] = B_item; - } - - int result = fairRations(B); - - fout << result << "\n"; - - fout.close(); - - return 0; -} - -vector split_string(string input_string) { - string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) { - return x == y and x == ' '; - }); - - input_string.erase(new_end, input_string.end()); - - while (input_string[input_string.length() - 1] == ' ') { - input_string.pop_back(); - } - - vector splits; - char delimiter = ' '; - - size_t i = 0; - size_t pos = input_string.find(delimiter); - - while (pos != string::npos) { - splits.push_back(input_string.substr(i, pos - i)); - - i = pos + 1; - pos = input_string.find(delimiter, i); - } - - splits.push_back(input_string.substr(i, min(pos, input_string.length()) - i + 1)); - - return splits; -} diff --git a/Fair Rations/Problem Statement .txt b/Fair Rations/Problem Statement .txt deleted file mode 100644 index 5f42962..0000000 --- a/Fair Rations/Problem Statement .txt +++ /dev/null @@ -1,62 +0,0 @@ -You are the benevolent ruler of Rankhacker Castle, and today you're distributing bread. Your subjects are in a line, and some of them already have some loaves. Times are hard and your castle's food stocks are dwindling, so you must distribute as few loaves as possible according to the following rules: - - 1. Every time you give a loaf of bread to some person i, you must also give a loaf of bread to the person immediately in front of or behind them in the line (i.e., persons i+1 or i-1 ). - 2. After all the bread is distributed, each person must have an even number of loaves. - -Given the number of loaves already held by each citizen, find and print the minimum number of loaves you must distribute to satisfy the two rules above. If this is not possible, print NO. - -For example, the people in line have loaves B={4,5,6,7}. We can first give a loaf to i=3 and i=4 so B={4,5,7,8}. Next we give a loaf to i=2 and i=3 and have B={4,6,8,8} which satisfies our conditions. We had to distribute 4 loaves. - -Function Description - -Complete the fairRations function in the editor below. It should return an integer that represents the minimum number of loaves required. - -fairRations has the following parameter(s): - - B: an array of integers that represent the number of loaves each persons starts with . - -Input Format - -The first line contains an integer N , the number of subjects in the bread line. - -The second line contains N space-separated integers B[i] . - -Constraints - -2<=N<=1000 -1<=B[i]<=10, where 1<=i<=N - -Output Format - -Print a single integer taht denotes the minimum number of loaves that must be distributed so that every person has an even number of loaves. If it's not possible to do this, print NO. - -Sample Input 0 - -5 -2 3 4 5 6 - -Sample Output 0 - -4 - -Explanation 0 - -The initial distribution is (2,3,4,5,6). The requirements can be met as follows: - - Give 1 loaf of bread each to the second and third people so that the distribution becomes (2,4,5,5,6). - Give 1 loaf of bread each to the third and fourth people so that the distribution becomes (2,4,6,6,6). - -Each of the N subjects has an even number of loaves after 4 loaves were distributed. - -Sample Input 1 - -2 -1 2 - -Sample Output 1 - -NO - -Explanation 1 - -The initial distribution is (1,2). As there are only 2 people in the line, any time you give one person a loaf you must always give the other person a loaf. Because the first person has an odd number of loaves and the second person has an even number of loaves, no amount of distributed loaves will ever result in both subjects having an even number of loaves. diff --git a/Fizz Buzz/c#_solution.cs b/Fizz Buzz/c#_solution.cs deleted file mode 100644 index dd025df..0000000 --- a/Fizz Buzz/c#_solution.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; - -namespace FizzBuzz -{ - class Program - { - static void Main(string[] args) - { - for (int i = 1; i <= 100; i++) - { - if (i % 15 == 0) - { - Console.WriteLine("FizzBuzz"); - } - else if (i % 3 == 0) - { - Console.WriteLine("Fizz"); - } - else if (i % 5 == 0) - { - Console.WriteLine("Buzz"); - } - else - { - Console.WriteLine(i); - } - } - } - } -} diff --git a/Fizz Buzz/dart_solution.dart b/Fizz Buzz/dart_solution.dart deleted file mode 100644 index 371155f..0000000 --- a/Fizz Buzz/dart_solution.dart +++ /dev/null @@ -1,13 +0,0 @@ -main() { - for (int i = 1; i <= 100; i++) { - if (i % 15 == 0) { - print('fizzbuzz'); - } else if (i % 5 == 0) { - print('buzz'); - } else if (i % 3 == 0) { - print('fizz'); - } else { - print(i); - } - } -} diff --git a/Fizz Buzz/fizzbuzz.c b/Fizz Buzz/fizzbuzz.c deleted file mode 100644 index 4640b18..0000000 --- a/Fizz Buzz/fizzbuzz.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -void main() -{ - int i; - for(i=1;i<=100;i++) - { - if(i%3!=0 && i%5!=0) printf("%d\n", i); - if(i%3 == 0 && i%5!=0)printf("Fizz\n"); - if(i%5 == 0 && i%3!=0)printf("Buzz\n"); - if(i%5 == 0 && i%3==0)printf("FizzBuzz\n"); - } -} diff --git a/Fizz Buzz/fizzbuzz.cpp b/Fizz Buzz/fizzbuzz.cpp deleted file mode 100644 index 22eea15..0000000 --- a/Fizz Buzz/fizzbuzz.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include -using namespace std; -int main() -{ - for(int i=1;i<=100;i++){ - if((i%3 == 0) && (i%5==0)) - cout<<"FizzBuzz\n"; - else if(i%3 == 0) - cout<<"Fizz\n"; - else if(i%5 == 0) - cout<<"Buzz\n"; - else - cout< diff --git a/Fizz Buzz/python_solution.py b/Fizz Buzz/python_solution.py deleted file mode 100644 index a770bbf..0000000 --- a/Fizz Buzz/python_solution.py +++ /dev/null @@ -1,9 +0,0 @@ -for x in range(1, 100): - if (x % 15 == 0): - print "fizzbuzz" - elif x % 3 == 0: - print "fizz" - elif x % 5 == 0: - print "buzz" - else: - print x diff --git a/Fizz Buzz/ruby_solution.rb b/Fizz Buzz/ruby_solution.rb deleted file mode 100644 index 1d4bfee..0000000 --- a/Fizz Buzz/ruby_solution.rb +++ /dev/null @@ -1,14 +0,0 @@ -counter = 0 - -while counter < 100 -counter += 1 - if (counter % 3 == 0) && (counter % 5 == 0) - puts("Fizz Buzz") - elsif counter % 3 == 0 - puts("Fizz") - elsif (counter % 5 == 0) - puts("Buzz") - else puts(counter) - end -end -break diff --git a/Floodfill/Problem_statement.txt b/Floodfill/Problem_statement.txt deleted file mode 100644 index 9ddda57..0000000 --- a/Floodfill/Problem_statement.txt +++ /dev/null @@ -1,28 +0,0 @@ -For those who dont like regular images, ASCII Maps Inc. has created maps that are fully printable ASCII characters. Each map is a rectangular grid of lowercase English letters, where each letter stands for various locations. In particular, w stands for water and the other 25 letters represent various different land locations. For this problem, we are interested in counting the number of bodies of water on a given ASCII map. A body of water is a maximal set of contiguous grid squares on the ASCII map where each square in the body of water shares a boundary with at least one other square in the body of water. Thus, for two grid squares to be part of the same body of water, one must be above, below, to the left, or to the right of the other grid square. -Input -The first line of input consists of two space separated integers, r (1=r=50) and c (1=c=50), the number of rows and columns, respectively for the input map. The next r lines will each contain c lowercase English letters, representing the corresponding row of the input map. - -Output -On a line by itself, output the number of bodies of water in the input map. - -Sample test case 1: - -Input: -5 6 -waaaww -wawawc -bbbbwc -wwwwww -dddddd - -Output: -3 - -Sample test case 2: -Input: -2 8 -wxwxwxwx -xwxwxwxw - -Output: -8 diff --git a/Floodfill/solution.java b/Floodfill/solution.java deleted file mode 100644 index 2974a5a..0000000 --- a/Floodfill/solution.java +++ /dev/null @@ -1,53 +0,0 @@ -import java.util.Arrays; -import java.util.Scanner; - -public class water { -public static void main(String[] args){ -Scanner kb=new Scanner(System.in); -System.out.println("Enter the dimensions of the map:"); -int n=kb.nextInt(); -int m=kb.nextInt(); -System.out.println("Enter the map:"); -char[][] x=new char[n][m]; -for(int i=0;i=0&&r=0&&c= M or y < 0 or - y >= N or screen[x][y] != prevC or - screen[x][y] == newC): - return - - # Replace the color at (x, y) - screen[x][y] = newC - - # Recur for north, east, south and west - floodFillUtil(screen, x + 1, y, prevC, newC) - floodFillUtil(screen, x - 1, y, prevC, newC) - floodFillUtil(screen, x, y + 1, prevC, newC) - floodFillUtil(screen, x, y - 1, prevC, newC) - -# It mainly finds the previous color on (x, y) and -# calls floodFillUtil() -def floodFill(screen, x, y, newC): - prevC = screen[x][y] - floodFillUtil(screen, x, y, prevC, newC) - -# Driver Code -screen = [[1, 1, 1, 1, 1, 1, 1, 1], - [1, 1, 1, 1, 1, 1, 0, 0], - [1, 0, 0, 1, 1, 0, 1, 1], - [1, 2, 2, 2, 2, 0, 1, 0], - [1, 1, 1, 2, 2, 0, 1, 0], - [1, 1, 1, 2, 2, 2, 2, 0], - [1, 1, 1, 1, 1, 2, 1, 1], - [1, 1, 1, 1, 1, 2, 2, 1]] - -x = 4 -y = 4 -newC = 3 -floodFill(screen, x, y, newC) - -print ("Updated screen after call to floodFill:") -for i in range(M): - for j in range(N): - print(screen[i][j], end = ' ') - print() diff --git a/Generate Parentheses/Question.txt b/Generate Parentheses/Question.txt deleted file mode 100644 index 4b3c0df..0000000 --- a/Generate Parentheses/Question.txt +++ /dev/null @@ -1,11 +0,0 @@ -Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. - -For example, given n = 3, a solution set is: - -[ - "((()))", - "(()())", - "(())()", - "()(())", - "()()()" -] \ No newline at end of file diff --git a/Generate Parentheses/Solution b/Generate Parentheses/Solution deleted file mode 100755 index c1d065f..0000000 Binary files a/Generate Parentheses/Solution and /dev/null differ diff --git a/Generate Parentheses/Solution.cpp b/Generate Parentheses/Solution.cpp deleted file mode 100644 index 3153f05..0000000 --- a/Generate Parentheses/Solution.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -using namespace std; - -void generate(int n, int opening, int closing, string combination, vector& result) { - int size = combination.size(); - if(size == n && closing == opening) { - result.push_back(combination); - return; - } - - if((closing < opening) && (size > 0)) { - combination.push_back(')'); - generate(n, opening, closing+1, combination, result); - combination.pop_back(); - } - - if(size < n-1) { - combination.push_back('('); - generate(n, opening+1, closing, combination, result); - combination.pop_back(); - } -} - -vector generateParenthesis(int n) { - vector result; - string combination; - generate(2*n, 0, 0, combination, result); - return result; -} - -int main() { - - int n; - vector result; - - scanf("%d", &n); - - result = generateParenthesis(n); - - for(int i=0; i 9 (i.e. edit 10). Make sure simply calling the methods won't result in a crash. - -Sample Input 1: - -insertEnd "now is the time" -insertEnd "for all good men" -insertEnd "to come to the aid of their country" -print -search "come to the aid" -quit - -Sample Output 1: - -1 now is the time -2 for all good men -3 to come to the aid of their country -3 to come to the aid of their country - -Sample Input 2: - -insertEnd "now is the time" -insertEnd "for all good men" -insertEnd "to come to the aid of their country" -print -edit 2 "for all good people" -print -quit - -Sample Output 2: - -1 now is the time -2 for all good men -3 to come to the aid of their country -1 now is the time -2 for all good people -3 to come to the aid of their country - -Sample Input 3: - -insertEnd "now is the time" -insertEnd "for all good people" -insertEnd "to come to the aid of their country" -delete 2 -print -insert 2 "for all good people" -print -quit - -Sample Output 3: - -1 now is the time -2 to come to the aid of their country -1 now is the time -2 for all good people -3 to come to the aid of their country - -Sample Input 4: - -insertEnd "hello world" -insertEnd "how are you doing" -insertEnd "hello world" -search "hello world" -quit - -Sample Output 4: - -1 hello world -3 hello world - -Sample Input 5: - -insertEnd "hello world" -insertEnd "how are you doing" -insertEnd "hello world" -search "hello pluto" -print -quit - -Sample Output 5: - -not found -1 hello world -2 how are you doing -3 hello world - -Sample Input 6: - -insertEnd "hello world" -insertEnd "how are you doing" -insert 2 "hello pluto" -print -delete 3 -print -quit - -Sample Output 6: - -1 hello world -2 hello pluto -3 how are you doing -1 hello world -2 hello pluto - -Sample Input 7: - -insertEnd "now is the time" -insertEnd "for all good men" -insertEnd "to come to the aid of their country" -delete 4 -print -insert 4 "Patrick Henry or Charles Weller?" -print -insert 6 "it was neither" -print -quit - -Sample Output 7: - -1 now is the time -2 for all good men -3 to come to the aid of their country -1 now is the time -2 for all good men -3 to come to the aid of their country -4 Patrick Henry or Charles Weller? -1 now is the time -2 for all good men -3 to come to the aid of their country -4 Patrick Henry or Charles Weller? - -Sample Input 8: - -insertEnd "hello mercury" -insertEnd "hello venus" -insertEnd "hello world" -insertEnd "hello pluto" -insertEnd "how are you doing" -insert 4 "hello mars" -insert 5 "hello jupiter" -insert 6 "hello saturn" -print -search "doing" -quit - -Sample Output 8: - -1 hello mercury -2 hello venus -3 hello world -4 hello mars -5 hello jupiter -6 hello saturn -7 hello pluto -8 how are you doing -8 how are you doing - -Sample Input 9: - -insertEnd "hello mercury" -insertEnd "hello venus" -insertEnd "hello world" -insertEnd "hello pluto" -insertEnd "how are you doing" -insert 4 "hello mars" -insert 5 "hello jupiter" -print -delete 7 -print -quit - -Sample Output 9: - -1 hello mercury -2 hello venus -3 hello world -4 hello mars -5 hello jupiter -6 hello pluto -7 how are you doing -1 hello mercury -2 hello venus -3 hello world -4 hello mars -5 hello jupiter -6 hello pluto - -Sample Input 10: - -insertEnd "hello mercury" -insertEnd "hello venus" -insertEnd "hello world" -insertEnd "hello pluto" -insertEnd "how are you doing" -insert 4 "hello mars" -insert 5 "hello jupiter" -insert 6 "hello saturn" -insert 7 "hello neptune" -insert 8 "hello uranus" -print -quit - -Sample Output 10: - -1 hello mercury -2 hello venus -3 hello world -4 hello mars -5 hello jupiter -6 hello saturn -7 hello neptune -8 hello uranus -9 hello pluto -10 how are you doing - -Sample Input 11: - -insertEnd "hello mercury" -insertEnd "hello venus" -insertEnd "hello world" -insertEnd "hello pluto" -insertEnd "how are you doing" -insert 4 "hello mars" -insert 5 "hello jupiter" -print -insert 8 "I'm fine" -print -quit - -Sample Output 11: - -1 hello mercury -2 hello venus -3 hello world -4 hello mars -5 hello jupiter -6 hello pluto -7 how are you doing -1 hello mercury -2 hello venus -3 hello world -4 hello mars -5 hello jupiter -6 hello pluto -7 how are you doing -8 I'm fine - -Sample Input 12: - -insertEnd "hello mercury" -insertEnd "hello venus" -insertEnd "hello world" -insertEnd "hello pluto" -insertEnd "how are you doing" -insert 4 "hello mars" -insert 5 "hello jupiter" -print -edit 7 "I'm fine" -print -quit - -Sample Output 12: - -1 hello mercury -2 hello venus -3 hello world -4 hello mars -5 hello jupiter -6 hello pluto -7 how are you doing -1 hello mercury -2 hello venus -3 hello world -4 hello mars -5 hello jupiter -6 hello pluto -7 I'm fine - -Sample Input 13: - -insertEnd "hello world" -insertEnd "how are you doing" -insert 2 "hello pluto" -insert 1 "hello mercury" -insert 2 "hello venus" -insert 4 "hello mars" -insert 5 "hello jupiter" -print -quit - -Sample Output 13: - -1 hello mercury -2 hello venus -3 hello world -4 hello mars -5 hello jupiter -6 hello pluto -7 how are you doing \ No newline at end of file diff --git a/Implement a Line Editor with a Linked List/Solution.cpp b/Implement a Line Editor with a Linked List/Solution.cpp deleted file mode 100644 index 589df5d..0000000 --- a/Implement a Line Editor with a Linked List/Solution.cpp +++ /dev/null @@ -1,217 +0,0 @@ -//your linked list implementation here -#include -#include -#include -#include -using namespace std; -struct Node -{ -public: - string text; - Node * next = nullptr; -}; -class LinkedList -{ -public: - int size; - Node *head; - LinkedList() //when should constructor be private - { - head = nullptr; - size = 0; - } - Node* add(int index, string textToAdd) //returns the new head and inserts a new node (line) - { - int count = 1; - Node *curr = head; //curr points to the address of head - Node * toDeleteHead = head; - Node *newNode = new Node(); //needs the operating system to assign memory also struct dont need () - Node * toDeleteNew = newNode; - newNode->text = textToAdd; - /** - if(index>size+1){ - return head; - }**/ - if(head == nullptr){ - head = newNode; - delete toDeleteHead; - size++; - return head; - } - if(index ==0){ - newNode->next = curr; - size++; - return newNode; - } - while((curr->next) != nullptr){ - if(index == count){ - newNode->next = curr->next; - curr->next = newNode; - size++; - return head; - } - curr = curr->next; - count++; - } - if(index>count){ //I'm pretty sure this code never runs due to insert x method's print statement - //Node * toDelete = head; - cout<<"WOW U REALLY SCREWED UP \n"; - return nullptr; - } - curr->next = newNode; - newNode->next = nullptr; - size++; - return head; - } - void print(){ - int count = 1; - Node * temp = head; - while(temp != nullptr){ - cout<< count << " " <text<<"\n"; - temp = temp->next; - count++; - } - } - void search(const string look){ - int count = 1; - bool find = false; - Node * temp = head; - while(temp != nullptr){ - if((temp->text).find(look)!= string::npos){ - cout<text<<"\n"; - find = true; - } - temp = temp->next; - count++; - } - if(!find) - cout<<"not found" <<"\n"; - } - void edit(int index, const string textReplace){ - int count = 1; - bool find = false; - Node * temp = head; - while(temp != nullptr){ - if(count == index){ - temp->text = textReplace; - find = true; - break; - } - temp = temp->next; - count++; - } - if(!find){} - //cout<<"not found - edit" <<"\n"; - } - void deletetext(int index){ //delete 1 on empty needs to be fixed - int count = 1; - Node * prev = head; - if(index == 1){ - if(head != nullptr){ - Node * toDelete = head; - prev = nullptr; - head = head->next; - delete toDelete; - size--; //why was this not here before - } - } - while(prev != nullptr){ - if(prev->next ==nullptr){ //testing failed case - break; - } - if((count+1) == index){ - Node * toDelete = prev->next; - prev->next = prev->next->next; //prob should delete the value. - delete toDelete; - size--; - break; - } - count++; - prev = prev->next; - } - } -}; -//your line editor implementation here -class LineEditor -{ -public: - LinkedList list; - /* - void insertEnd(string s){ - list.head = list.add(1,s); - }*/ - void insert(int index, string s){ - list.head = list.add(index, s); - } - void deletetext(int index){ - list.deletetext(index); - } - void edit(int index, string s){ - list.edit(index,s); - } - void print(){ - list.print(); - } - void search(string s){ - list.search(s); - } -}; - -int main() //need to do more than "9 lines" -{ - //your code to invoke line editor here - LineEditor le; - string s; - locale loc; - while (s != "quit"){ - getline (cin,s); - if(s.empty()){ - //cout<<"you inputted like an empty string\n"; - s=""; - } - if(s.substr(s.find("\"")+1,s.find_last_of("\"")-1-s.find_first_of("\"")).size()>80){ - //cout<<"you inputted text with more than 80 chars\n"; - s=""; - } - if(s.substr(s.find(" ")+1,1)=="-"){ - //cout<<"you inputted a negative index\n"; - s=""; - } - int temp = s.find(" "); - for (int i=0; i0){ //&& !(stoi(s.substr(s.find(" ")+1,s.find_last_of(" ")-1-s.find_first_of(" ")))>le.list.size) - int indexNumber = stoi(s.substr(s.find(" ")+1,s.find_last_of(" ")-1-s.find_first_of(" "))); - /**le.insert(stoi(s.substr(s.find(" ")+1,1))-1, s.substr(s.find("\"")+1,s.find_last_of("\"")-1-s.find_first_of("\"")));//int to string**/ - /*if(stoi(s.substr(s.find(" ")+1,s.find_last_of(" ")-1-s.find_first_of(" ")))==le.list.size){ - le.insert(le.list.size, s.substr(s.find("\"")+1,s.find_last_of("\"")-1-s.find_first_of("\""))); - } - else{*/ - if(!(le.list.size==0 && indexNumber-1>0) && indexNumber-1<=le.list.size){ - le.insert(indexNumber-1, s.substr(s.find("\"")+1,s.find_last_of("\"")-1-s.find_first_of("\""))); - } - } - //if(s.substr(s.find(" ")+1,1)!="-" - - } - if(s.find("search") != string::npos){ - le.search(s.substr(s.find("\"")+1,s.find_last_of("\"")-1-s.find_first_of("\""))); - } - if(s.find("print") != string::npos){ - le.print(); - } - if(s.find("edit") != string::npos){ - le.edit(stoi(s.substr(s.find(" ")+1,s.find_last_of(" ")-1-s.find_first_of(" "))), s.substr(s.find("\"")+1,s.find_last_of("\"")-1-s.find_first_of("\""))); - } - if(s.find("delete") != string::npos){ - le.deletetext(stoi(s.substr(s.find(" ")+1,s.find_last_of(" ")-1-s.find_first_of(" ")))); - } - - } -} \ No newline at end of file diff --git a/In search of an easy problem/problem_statement.txt b/In search of an easy problem/problem_statement.txt deleted file mode 100644 index 3790d35..0000000 --- a/In search of an easy problem/problem_statement.txt +++ /dev/null @@ -1,17 +0,0 @@ -When preparing a tournament, Codeforces coordinators try treir best to make the first problem as easy as possible. This time the coordinator -had chosen some problem and asked n people about their opinions. Each person answered whether this problem is easy or hard. - -If at least one of these n people has answered that the problem is hard, the coordinator decides to change the problem. For the given -responses, check if the problem is easy enough. - -Input -The first line contains a single integer n(1 ≤ n ≤ 100) — the number of people who were asked to give their opinions. - -The second line contains n integers, each integer is either 0 or 1. If i-th integer is 0, then i-th person thinks that the problem is -easy; if it is 1, then i-th person thinks that the problem is hard. - -Output -Print one word: "EASY" if the problem is easy according to all responses, or "HARD" if there is at least one person who thinks the -problem is hard. - -You may print every letter in any register: "EASY", "easy", "EaSY" and "eAsY" all will be processed correctly. \ No newline at end of file diff --git a/In search of an easy problem/sol.cpp b/In search of an easy problem/sol.cpp deleted file mode 100644 index af4420e..0000000 --- a/In search of an easy problem/sol.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -#define MAX 100005 -#define pb push_back -#define mp make_pair -#define M 1000000007 -#define fi first -#define se second -#define inp(i, n, a) for(int i=0;i>a[i]; -#define int long long -using namespace std; - -signed main() -{ -// ios_base::sync_with_stdio(false); -// cin.tie(NULL); - -int n; -cin >> n; -int a, sum = 0; -for(int i=0; i> a; - sum += a; -} -cout << (sum ? "HARD":"EASY"); -return 0; -} \ No newline at end of file diff --git a/Insertion_sort_using_classes/insertion_sort.cpp b/Insertion_sort_using_classes/insertion_sort.cpp deleted file mode 100644 index 8aaa360..0000000 --- a/Insertion_sort_using_classes/insertion_sort.cpp +++ /dev/null @@ -1,182 +0,0 @@ -#include -using namespace std; - -/* Hi I am using my own class to use in insertion sort function*/ - -template -class LinearList{ - private: - int MaxSize; - Item *element; // 1D dynamic array - int len; - public: - /* Default constructor. - * Should create an empty list that not contain any elements*/ - LinearList() - { - element=nullptr; - len=0; - }; - - /* This constructor should create a list containing MaxSize elements. You can intialize the elements with any values.*/ - LinearList(const int& MaxListSize) - { - MaxSize=MaxListSize; - element = new Item[MaxSize]; - len=0; - - }; - - /* Destructor. - * Must free all the memory contained by the list */ - ~LinearList(){}; - - /* Indexing operator. - * It should behave the same way array indexing does. i.e, - * LinearList L; - * L[0] should refer to the first element; - * L[1] to the second element and so on. - * */ - Item& operator[](const int& i) - { - return element[i]; - }; //return i'th element of list - - /* Returns true if the list is empty, false otherwise. - * */ - bool isEmpty() - { - if(len==0) - { - return true; - } - else - { - return false; - } - }; - - /* Returns the actual length (number of elements) in the list. - * */ - int length() - { - return len; - }; - - /* Returns the maximum size of the list. - * */ - int maxSize() - { - return maxSize; - }; - - /* Returns the k-th element of the list. - * */ - Item returnListElement(const int k) - { - return element[k-1]; - }; - /* Set x to the k-th element and - * return true if k-th element is present otherwise return false. - * */ - bool find(const int k, Item& x) - { - if(x==element[k-1]) - { - return true; - } - else - { - - return false; - } - }; - - /* Search for x and - * return the position if found, else return 0. - * */ - int search(Item& x) - { - for(int i=0;ik;i--) - { - element[i]=element[i-1]; - } - element[k]=x; - len=len+1; - }; - - -}; - -//insertion sort function -void insertionSort(LinearList& A) - { - int i,j,temp,len; - i=j=0; - len=A.length(); - j=len; - for(i=1;i-1;j--) - { - if(temp> n; - LinearList l(100); - - for(i=0;i> temp; - l.insert(i,temp); - } - insertionSort(l); - for(i=0;i -#include - -int maxSubarraySum(int a[], int l) { - int max = INT_MIN, max_here = 0; - - for (int i = 0; i < l; i++) { - max_here = max_here + a[i]; - if (max < max_here) max = max_here; - if (max_here < 0) max_here = 0; - } - - return max; -} - -// int maxSubarraySum(int a[], int l) { -// int max = a[0], max_here = a[0]; - -// for (int i = 0; i < l; i++) { -// if (max_here > 0) max_here += a[i]; -// else max_here = a[i]; -// if (max_here > max) max = max_here; -// } - -// return max; -// } - -int main(int argc, char *argv[]) { - int arr[] = {-2, -3, 4, -1, -2, 1, 5, -3}; - int l = sizeof(arr) / sizeof(int); - - int m = maxSubarraySum(arr, l); - - printf("%d is the max subarray sum\n", m); - - return 0; -} \ No newline at end of file diff --git a/Kadane's Algorithm/kadane.cpp b/Kadane's Algorithm/kadane.cpp deleted file mode 100644 index 0101507..0000000 --- a/Kadane's Algorithm/kadane.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -using namespace std; - -int maxSubarraySum(vector a, int l) { - int max = INT_MIN, max_here = 0; - - for (int i = 0; i < l; i++) { - max_here = max_here + a[i]; - if (max < max_here) max = max_here; - if (max_here < 0) max_here = 0; - } - - return max; -} - - -int main() { - vector arr({-2, -3, 4, -1, -2, 1, 5, -3}); - int l = arr.size(); - - int m = maxSubarraySum(arr, l); - - cout< N. - PERFORM Y-PARA VARYING I FROM B BY 1 UNTIL C = N. - MOVE K TO P. - DISPLAY "THE LCM IS " P. - - DISPLAY "Enter Number of Head". - ACCEPT num. - DISPLAY "Enter number of legs". - ACCEPT num2. - PERFORM headleg-PARA. - if count1 equals 2 DISPLAY "NONE" - STOP RUN. - - X-PARA. - ACCEPT A(I). - IF (B < A(I)) - MOVE A(I) TO B. - - Y-PARA. - MOVE 0 TO C. - COMPUTE D = D + 1. - PERFORM Z-PARA VARYING J FROM 1 BY 1 UNTIL J > N. - - Z-PARA. - COMPUTE K = B * D. - DIVIDE K BY A(J) GIVING Q REMAINDER R. - IF (R = 0) - COMPUTE C = C + 1. - - headleg-PARA. - PERFORM VARYING chickens FROM 0 BY 1 UNTIL chickens >= num - COMPUTE dogs = num - chickens - COMPUTE result =2 * chickens - COMPUTE result1 =4 * dogs - COMPUTE result2 = result + result1 - IF result2 EQUALS num2 - DISPLAY "[", chickens,",",dogs,"]" - SET count1 to 1 - ELSE IF count1 equals to 1 set count1 to 1 - else set count1 to 2 - END-IF - END-PERFORM. diff --git a/Least_Common_Multiple/Problem.txt b/Least_Common_Multiple/Problem.txt deleted file mode 100644 index 83e009c..0000000 --- a/Least_Common_Multiple/Problem.txt +++ /dev/null @@ -1,6 +0,0 @@ -## Problem: - -The LCM of two integers n1 and n2 is the smallest positive integer that is perfectly -divisible by both n1 and n2 (without a remainder). For example: the LCM of 72 and 120 is 360. - -write a program written in COBOL that will compute the LCM of 2 numbers diff --git a/Lily's Homework/Question.txt b/Lily's Homework/Question.txt deleted file mode 100644 index 502c95c..0000000 --- a/Lily's Homework/Question.txt +++ /dev/null @@ -1,11 +0,0 @@ -Consider an array of distinct integers, arr = [a[0], a[1], ..., a[n-1]]. George can swap any two elements of the array any number of times. An array is beautiful if the sum of |arr[i] - arr[i-1]|among 0< i < n is minimal. - -Given the array , determine and return the minimum number of swaps that should be performed in order to make the array beautiful. - -For example, arr = [7, 15, 12, 3]. One minimal array is [3, 7, 12, 15]. To get there, George performed the following swaps: - -Swap Result - [7, 15, 12, 3] -3 7 [3, 15, 12, 7] -7 15 [3, 7, 12, 15] -It took 2 swaps to make the array beautiful. This is minimal among the choice of beautiful arrays possible. \ No newline at end of file diff --git a/Lily's Homework/solution.py b/Lily's Homework/solution.py deleted file mode 100644 index 8b29419..0000000 --- a/Lily's Homework/solution.py +++ /dev/null @@ -1,26 +0,0 @@ -def lilysHomework(arr): - m = {} - for i in range(len(arr)): - m[arr[i]] = i - sorted_arr = sorted(arr) - res = 0 - for i in range(len(arr)): - if(arr[i] != sorted_arr[i]): - res += 1 - x = m[sorted_arr[i]] - m[ arr[i] ] = m[ sorted_arr[i]] - arr[i],arr[x] = sorted_arr[i],arr[i] - return res - -if __name__ == '__main__': - fptr = open(os.environ['OUTPUT_PATH'], 'w') - - n = int(input()) - - arr = list(map(int, input().rstrip().split())) - - result = min(lilysHomework(list(arr)), lilysHomework(list(arr[::-1]))) - - fptr.write(str(result) + '\n') - - fptr.close() diff --git a/Magic-Spells-LCS/problem.txt b/Magic-Spells-LCS/problem.txt deleted file mode 100644 index 20df9df..0000000 --- a/Magic-Spells-LCS/problem.txt +++ /dev/null @@ -1,19 +0,0 @@ -This is from https://www.hackerrank.com/challenges/magic-spells/problem - -You are battling a powerful dark wizard. He casts his spells from a distance, giving you only a few seconds to react and conjure -your counterspells. For a counterspell to be effective, you must first identify what kind of spell you are dealing with. - -The wizard uses scrolls to conjure his spells, and sometimes he uses some of his generic spells that restore his stamina. In that -case, you will be able to extract the name of the scroll from the spell. Then you need to find out how similar this new spell is -to the spell formulas written in your spell journal. - - -Input Format -The wizard will read scrolls, which are hidden from you. -Every time he casts a spell, it's passed as an argument to your counterspell function. - - -Output Format -After identifying the given spell, print its name and power. -If it is a generic spell, find a subsequence of letters that are contained in both the spell name and your spell journal. -Among all such subsequences, find and print the length of the longest one on a new line. diff --git a/Magic-Spells-LCS/solution.cpp b/Magic-Spells-LCS/solution.cpp deleted file mode 100644 index 8d2c209..0000000 --- a/Magic-Spells-LCS/solution.cpp +++ /dev/null @@ -1,142 +0,0 @@ -#include -#include -#include -using namespace std; - -class Spell { - private: - string scrollName; - public: - Spell(): scrollName("") { } - Spell(string name): scrollName(name) { } - virtual ~Spell() { } - string revealScrollName() { - return scrollName; - } -}; - -class Fireball : public Spell { - private: int power; - public: - Fireball(int power): power(power) { } - void revealFirepower(){ - cout << "Fireball: " << power << endl; - } -}; - -class Frostbite : public Spell { - private: int power; - public: - Frostbite(int power): power(power) { } - void revealFrostpower(){ - cout << "Frostbite: " << power << endl; - } -}; - -class Thunderstorm : public Spell { - private: int power; - public: - Thunderstorm(int power): power(power) { } - void revealThunderpower(){ - cout << "Thunderstorm: " << power << endl; - } -}; - -class Waterbolt : public Spell { - private: int power; - public: - Waterbolt(int power): power(power) { } - void revealWaterpower(){ - cout << "Waterbolt: " << power << endl; - } -}; - -class SpellJournal { - public: - static string journal; - static string read() { - return journal; - } -}; -string SpellJournal::journal = ""; - -void counterspell(Spell *spell) { - - /* Enter your code here */ - if (auto f = dynamic_cast(spell)) { - f->revealFirepower(); - } - else if (auto f = dynamic_cast(spell)) { - f->revealFrostpower(); - } - else if (auto f = dynamic_cast(spell)) { - f->revealThunderpower(); - } - else if (auto f = dynamic_cast(spell)) { - f->revealWaterpower(); - } - else { - auto find = [](const string& A, const string& B) -> int - { - std::vector> LCS(A.length() + 1); - for (int i = 0; i < LCS.size(); i++) - LCS[i].resize(B.length() + 1); - - for (int i = 1; i <= A.length(); i++) { - for (int j = 1; j <= B.length(); j++) { - if (A[i - 1] == B[j - 1]) { - LCS[i][j] = LCS[i - 1][j - 1] + 1; - } - else { - LCS[i][j] = max(LCS[i - 1][j], LCS[i][j - 1]); - } - } - } - return LCS[A.length()][B.length()]; - }; - - string s1 = spell->revealScrollName(); - string s2 = SpellJournal::read(); - int len = 0; - if (s1.length() > 0 && s2.length() > 0) - len = find(&s1[0], &s2[0]); - cout << len << endl; - } -} - -class Wizard { - public: - Spell *cast() { - Spell *spell; - string s; cin >> s; - int power; cin >> power; - if(s == "fire") { - spell = new Fireball(power); - } - else if(s == "frost") { - spell = new Frostbite(power); - } - else if(s == "water") { - spell = new Waterbolt(power); - } - else if(s == "thunder") { - spell = new Thunderstorm(power); - } - else { - spell = new Spell(s); - cin >> SpellJournal::journal; - } - return spell; - } -}; - -int main() { - int T; - cin >> T; - Wizard Arawn; - while(T--) { - Spell *spell = Arawn.cast(); - counterspell(spell); - } - return 0; -} diff --git a/Max_Sum_Contiguous_Subarray/Question.txt b/Max_Sum_Contiguous_Subarray/Question.txt deleted file mode 100644 index 196a634..0000000 --- a/Max_Sum_Contiguous_Subarray/Question.txt +++ /dev/null @@ -1,9 +0,0 @@ -Find the contiguous subarray within an array (containing at least one number) which has the largest sum. - -For example: - -Given the array [-2,1,-3,4,-1,2,1,-5,4], - -the contiguous subarray [4,-1,2,1] has the largest sum = 6. - -For this problem, return the maximum sum. diff --git a/Max_Sum_Contiguous_Subarray/Readme.md b/Max_Sum_Contiguous_Subarray/Readme.md deleted file mode 100644 index d77b39a..0000000 --- a/Max_Sum_Contiguous_Subarray/Readme.md +++ /dev/null @@ -1 +0,0 @@ -A good tricky problem. diff --git a/Max_Sum_Contiguous_Subarray/Solution.cpp b/Max_Sum_Contiguous_Subarray/Solution.cpp deleted file mode 100644 index d7e130c..0000000 --- a/Max_Sum_Contiguous_Subarray/Solution.cpp +++ /dev/null @@ -1,20 +0,0 @@ -int Solution::maxSubArray(const vector &A) { - int s=INT_MIN,n = A.size(),i,j,m=0,mi=INT_MAX,ma = INT_MIN; - int arr[n]; - memset(arr,0,sizeof(arr)); - - for(i=0;i -using namespace std; - -// We declare the vector of factors for storing the -vector factors; - -// function to find out the factors of a number -void findFactors(int n) -{ - // we loop until the i reaches the sqrt(n) - for (int i = 1; i * i <= n; i++) { - - // we check if i is a factor of n - if (n % i == 0) { - - // if both the factors are same - // only push one factor - if ((n / i) == i) { - factors.push_back(i); - } - else { - - // factor1 is pushed - factors.push_back(n / i); - - // factor2 is pushed - factors.push_back(i); - } - } - } -} - -int findProduct(int n) -{ - // initialise the product with -1 - int product = -1; - int si = factors.size(); - - for (int i = 0; i < si; i++) - for (int j = 0; j < si; j++) - for (int k = 0; k < si; k++) { - - // we find the sum of factors - // and store it in s - int s = factors[i] + factors[j] + factors[k]; - - // we check whether the fourth - // factor exists or not - if (binary_search(factors.begin(), factors.end(), n - s)) { - // product of factors - int p = factors[i] * factors[j] * factors[k] * (n - s); - - // we check whether we have a better - // p now if yes update - if (p > product) - product = p; - } - } - - return product; -} - -// Driver code -int main() -{ - int n = 10; - - // intializes the vectors with the divisors of n - findFactors(n); - - // sorts the factors vector - sort(factors.begin(), factors.end()); - - // prints out the maximised product. - cout << findProduct(n); - return 0; -} diff --git a/Maximum sum of digits/code.cpp b/Maximum sum of digits/code.cpp deleted file mode 100644 index 80e4c4c..0000000 --- a/Maximum sum of digits/code.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include -#define MAX 100005 -#define pb push_back -#define mp make_pair -#define M 1000000007 -#define fi first -#define se second -#define inp(i, n, a) for(int i=0;i>a[i]; -#define int long long -using namespace std; - -int sod(int n) -{ - int res = 0; - while(n) - { - res = res + n%10; - n /= 10; - } - return res; -} - -signed main() -{ -// ios_base::sync_with_stdio(false); -// cin.tie(NULL); - -string n; -cin >> n; -string num1 = "", num2 = ""; -for(int i=0; i - -using namespace std; - -int main() -{ - int index1,index2,index3; - long int input,perimeter,perimax=0; - cin>>input; - long int arr[input]; - for(int i=0;i>arr[i]; - } - sort(arr,arr+input); - for(int i=input-1;i>=2;i--) - { - if(arr[i-2]+arr[i-1]>arr[i] ) - { - - perimeter=arr[i-2]+arr[i-1]+arr[i]; - if(perimeter>perimax) - { - index1=arr[i-2]; - index2=arr[i-1]; - index3=arr[i]; - perimax=perimeter; - - } - - } - } - - - if(perimax>0) - { - cout< { - if (arr.length <= 1) { - return arr; - } - - let midIdx = Math.floor(arr.length / 2); - let left = arr.slice(0, midIdx); - let right = arr.slice(midIdx); - - let leftSorted = mergeSort(left); - let rightSorted = mergeSort(right); - - return merge(leftSorted, rightSorted); - -}; - -const merge = (arr1, arr2) => { - let merged = []; - - while (arr1.length && arr2.length) { - if (arr1[0] < arr2[0]) { - merged.push(arr1.shift()); - } else { - merged.push(arr2.shift()); - } - } - - return [...merged, ...arr1, ...arr2]; -}; - -console.log(mergeSort(myArray)); \ No newline at end of file diff --git a/Mergesort-JS/question.txt b/Mergesort-JS/question.txt deleted file mode 100644 index 3d3188a..0000000 --- a/Mergesort-JS/question.txt +++ /dev/null @@ -1,5 +0,0 @@ -Sort the given by implementing Quicksort -[2, 4, 1, 6, -7, 8, 5, 9, 3, 4] - -answer: -[ -7, 1, 2, 3, 4, 4, 5, 6, 8, 9 ] \ No newline at end of file diff --git a/Merging_Two_Sorted_Array/question.txt b/Merging_Two_Sorted_Array/question.txt deleted file mode 100644 index 43fe95f..0000000 --- a/Merging_Two_Sorted_Array/question.txt +++ /dev/null @@ -1 +0,0 @@ -Given two sorted arrays arr1[] and arr2[] in non-decreasing order with size n and m. The task is to merge the two sorted arrays into one sorted array (in non-decreasing order) diff --git a/Merging_Two_Sorted_Array/solution.cpp b/Merging_Two_Sorted_Array/solution.cpp deleted file mode 100644 index a61ab49..0000000 --- a/Merging_Two_Sorted_Array/solution.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -using namespace std; -int main() - { - int t; - cin>>t; - while(t--) - { - int x,y; - cin>>x>>y; - long a[x+1],b[y+1]; - for(int i=0;i>a[i]; - for(int i=0;i>b[i]; - - int i=0,j=0; - vector vec; - while(ib[j]) - { - vec.push_back(b[j]); - j++; - } - else if(a[i]==b[j]) - { - vec.push_back(a[i]); - vec.push_back(b[j]); - i++; - j++; - } - } - while(i -using namespace std; - -void copyArr(int from[], int si, int ei, int * to) { - // while (si <= ei) *to++ = *si++; - while (si <= ei) { - *to = from[si]; - ++si; - ++to; - } -} - - -void mergeSortedArray(int arr[], int si, int ei, int mid) { - - int tmp_A[100]; - int tmp_B[100]; - - copyArr(arr, si, mid, tmp_A); - copyArr(arr, mid + 1, ei, tmp_B); - - int i = 0; - int j = 0; - int k = si; - - //while a has elements and b has elements, I have to do something - int size_A = mid - si + 1; - int size_B = ei - (mid + 1) + 1; - - while (i < size_A && j < size_B) { - if (tmp_A[i] < tmp_B[j]) { - arr[k] = tmp_A[i]; - i++; - k++; - } - else { - arr[k++] = tmp_B[j++]; - } - } - - while (i < size_A) { - arr[k++] = tmp_A[i++]; - } - - while (j < size_B) arr[k++] = tmp_B[j++]; - - -} - - -void mergeSort(int arr[], int si, int ei) { - if (si >= ei) { - //no elements - return; - } - - int mid = (si + ei) / 2; - //sort the left part - mergeSort(arr, si, mid); - mergeSort(arr, mid + 1, ei); - - mergeSortedArray(arr, si, ei, mid); - -} - - -int main() { - int arr[100]; - int n; - cin >> n; - inputArr(arr, n); - - mergeSort(arr, 0, n - 1); - - printArr(arr, n); -} diff --git a/Mersort_In_C++/mergesort.txt b/Mersort_In_C++/mergesort.txt deleted file mode 100644 index ba3cfe6..0000000 --- a/Mersort_In_C++/mergesort.txt +++ /dev/null @@ -1,13 +0,0 @@ -Merge Sort is a Divide and Conquer algorithm. It divides input array in -two halves, calls itself for the two halves and then merges the two sorted halves. -Algorithm: -MergeSort(arr[], l, r) -If r > l -1. Find the middle point to divide the array into two halves: - middle m = (l+r)/2 -2. Call mergeSort for first half: - Call mergeSort(arr, l, m) -3. Call mergeSort for second half: - Call mergeSort(arr, m+1, r) -4. Merge the two halves sorted in step 2 and 3: - Call merge(arr, l, m, r) \ No newline at end of file diff --git a/Mislove Has Lost an Array/Question.txt b/Mislove Has Lost an Array/Question.txt deleted file mode 100644 index 23182ac..0000000 --- a/Mislove Has Lost an Array/Question.txt +++ /dev/null @@ -1,17 +0,0 @@ -Mislove had an array a1, a2, ⋯, an of n positive integers, but he has lost it. He only remembers the following facts about it: - -1)The number of different numbers in the array is not less than l and is not greater than r. -2)For each array's element ai either ai=1 or ai is even and there is a number ai/2 in the array. - -For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn't be [1,2,2,4,8] because this array contains 4 different numbers; it couldn't be [1,2,2,3,3] because 3 is odd and isn't equal to 1; and it couldn't be [1,1,2,2,16] because there is a number 16 in the array but there isn't a number 16/2=8. - -According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array. - -Input-1 -4 2 2 -Output -5 7 -Input-2 -5 1 5 -Output -5 31 diff --git a/Mislove Has Lost an Array/Solution.cpp b/Mislove Has Lost an Array/Solution.cpp deleted file mode 100644 index 841440f..0000000 --- a/Mislove Has Lost an Array/Solution.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -using namespace std; -int main() -{ - long long int i,mini=1,mine=0,maxi=1,maxo=0,n,s,e; - cin>>n>>s>>e; - - for(i=1;i<=s-1;i++) - { - mini=2*mini; - mine+=mini; - } -mine+=n-s+1; - -for(i=1;i<=e-1;i++) -{ - maxi=2*maxi; - maxo+=maxi; -} -maxo+=1; - - -maxo+=(n-e)*(maxi); -cout< -#include -#include - -using namespace std; - -void input(int *n, vector *stones) { - cin >> *n; - vector v(*n); - for (int i = 0; i < *n; ++i) { - cin >> v[i]; - int temp = v[i]; - int j = 0; - int f = 1; - for (int l = 2; l * l <= temp; ++l) { - if (temp % l == 0) { - if (j == l) { - ++f; - if (f == 2) { - v[i] /= j * j; - f = 0; - } - } else { - f = 1; - j = l; - } - temp /= l; - --l; - } - } - if (temp == j) { - ++f; - if (f == 2) { - v[i] /= j * j; - } - } - } - sort(v.begin(), v.end()); - stones->push_back(1); - for (int i = 1; i < *n; ++i) { - if (v[i] == v[i - 1]) { - ++stones->at(stones->size() - 1); - } else { - stones->push_back(1); - } - } -} - -int necklace(size_t n, const std::vector &stones, int mod) { - std::vector data_first(n); - std::vector data_second(n); - std::vector> c(n + 2, std::vector(n + 2)); - std::vector fact(n + 2); - c[0][0] = 1; - fact[0] = 1; - for (int i = 1; i <= n + 1; ++i) { - fact[i] = (fact[i - 1] * i) % mod; - c[i][0] = 1; - for (int j = 1; j <= n + 1; ++j) { - c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod; - } - } - int count = stones[0] - 1; - data_second[stones[0] - 1] = fact[stones[0]]; - for (int stone = 1; stone < stones.size(); ++stone) { - if (stones[stone] != 0) { - std::vector temp_first = std::move(data_first); - std::vector temp_second = std::move(data_second); - data_first = std::vector(n); - data_second = std::vector(n); - for (int i = 0; i < n; ++i) { - if (temp_first[i] != 0) { - for (int l = 1; l <= stones[stone]; ++l) { - for (int j = 0; j <= std::min(i, l); ++j) { - long long temp1 = 0; - if (count >= i) { - temp1 = (c[count - i][l - j] * c[i][j]) % mod; - temp1 = (temp1 * c[stones[stone] - 1][l - 1]) % mod; - temp1 = (temp1 * fact[stones[stone]]) % mod; - temp1 = (temp1 * temp_first[i]) % mod; - } - long long temp2 = 0; - if (count + 1 >= i) { - temp2 = - (c[count - i + 1][l - j] * c[i][j]) % mod; - temp2 = (temp2 * c[stones[stone] - 1][l - 1]) % mod; - temp2 = (temp2 * fact[stones[stone]]) % mod; - temp2 = (temp2 * temp_first[i]) % mod; - } - temp2 = (temp2 * 2) % mod; - temp2 = (temp2 - temp1) % mod; - if (temp2 < 0) { - temp2 += mod; - } - data_first[i - j + stones[stone] - l] = - (data_first[i - j + stones[stone] - l] + - temp2) % mod; - if (l - j >= 2) { - temp1 = - (c[count - i][l - j - 2] * c[i][j]) % mod; - temp1 = (temp1 * c[stones[stone] - 1][l - 1]) % mod; - temp1 = (temp1 * fact[stones[stone]]) % mod; - temp1 = (temp1 * temp_first[i]) % mod; - data_second[i - j + stones[stone] - l] = - (data_second[i - j + stones[stone] - l] + - temp1) % mod; - } - } - } - } - if (temp_second[i] != 0) { - for (int l = 1; l <= stones[stone]; ++l) { - for (int j = 0; j <= std::min(i, l); ++j) { - long long temp1 = 0; - if (count >= i) { - temp1 = (c[count - i][l - j] * c[i][j]) % mod; - temp1 = (temp1 * c[stones[stone] - 1][l - 1]) % mod; - temp1 = (temp1 * fact[stones[stone]]) % mod; - temp1 = (temp1 * temp_second[i]) % mod; - data_second[i - j + stones[stone] - l] = - (data_second[i - j + stones[stone] - l] + - temp1) % mod; - } - long long temp2 = 0; - if (count + 1 >= i) { - temp2 = - (c[count - i + 1][l - j] * c[i][j]) % mod; - temp2 = (temp2 * c[stones[stone] - 1][l - 1]) % mod; - temp2 = (temp2 * fact[stones[stone]]) % mod; - temp2 = (temp2 * temp_second[i]) % mod; - } - temp2 = (temp2 * 2) % mod; - temp1 = (temp1 * 2) % mod; - temp2 = (temp2 - temp1) % mod; - if (temp2 < 0) { - temp2 += mod; - } - data_first[i - j + stones[stone] - l] = - (data_first[i - j + stones[stone] - l] + - temp2) % mod; - if (l - j >= 2) { - temp1 = - (c[count - i][l - j - 2] * c[i][j]) % mod; - temp1 = (temp1 * c[stones[stone] - 1][l - 1]) % mod; - temp1 = (temp1 * fact[stones[stone]]) % mod; - temp1 = (temp1 * temp_second[i]) % mod; - data_second[i - j + stones[stone] - l] = - (data_second[i - j + stones[stone] - l] + - temp1) % mod; - } - } - } - } - } - count += stones[stone]; - } - } - return (int) ((data_first[0] + data_second[0]) % mod); -} - -int rek(std::vector *v, int last, int first) { - int res = 0; - int k = 0; - for (int &a : *v) { - if (a != -1) { - ++k; - if (a != last) { - int temp = a; - a = -1; - if (first == -1) { - res += rek(v, temp, temp); - } else { - res += rek(v, temp, first); - } - a = temp; - } - } - } - if (k == 0) { - if (first != last) { - return 1; - } - return 0; - } - return res; -} - -bool test() { - int n = rand() % 10 + 1; - int k = rand() % 10 + 1; - std::vector stones(k); - std::vector v(n); - for (int i = 0; i < n; ++i) { - v[i] = rand() % k; - ++stones[v[i]]; - } - std::sort(stones.rbegin(), stones.rend()); - if (rek(&v, -1, -1) != necklace(n, stones, 1000000007)) { - std::cout << n << " " << k << std::endl; - for (int i = 0; i < n; ++i) { - std::cout << v[i] << " "; - } - std::cout << std::endl; - std::cout << rek(&v, -1, -1) << " "; - std::cout << necklace(n, stones, 1000000007) << std::endl; - return false; - } - return true; -} - -void tests() { - srand(16); - int c = 0; - int count = 1000; - while (c++ < count && test()); -} - -int main() { - int n; - std::vector stones; - input(&n, &stones); - std::cout << necklace((size_t) n, stones, 1000000007) << std::endl; - fclose(stdin); - fclose(stdout); -// tests(); - return 0; -} diff --git a/Necklace/statement.pdf b/Necklace/statement.pdf deleted file mode 100644 index 5a9f14e..0000000 Binary files a/Necklace/statement.pdf and /dev/null differ diff --git a/Octal Decimal Calculator/Octal Decimal Calculator.txt b/Octal Decimal Calculator/Octal Decimal Calculator.txt deleted file mode 100644 index 41b563a..0000000 --- a/Octal Decimal Calculator/Octal Decimal Calculator.txt +++ /dev/null @@ -1,9 +0,0 @@ -Given an octal number it is required to convert to decimal and print it on the console - -Example: - -The octal number 567 is entered. - -The system calculates the equivalent number in decimal that is 375 and prints it on the console - -The decimal number for octal 567 is: 357 \ No newline at end of file diff --git a/Octal Decimal Calculator/OctalDecimalCalculator.java b/Octal Decimal Calculator/OctalDecimalCalculator.java deleted file mode 100644 index 596c7d5..0000000 --- a/Octal Decimal Calculator/OctalDecimalCalculator.java +++ /dev/null @@ -1,43 +0,0 @@ -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; - -public class OctalDecimalCalculator { - - private static int BASE_8 = 8; - private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - private static final String RESULT_TEMPLATE = "The decimal number for octal %s is: %s"; - - public static void main(String[] args){ - - System.out.println("Please input octal number to convert"); - try { - String octal = br.readLine(); - String decimal = convertOctalToDecimal(Integer.parseInt(octal)); - - System.out.println(String.format(RESULT_TEMPLATE, octal, decimal)); - } catch (IOException e) { - e.printStackTrace(); - } - - } - - public static String convertOctalToDecimal(int octal){ - int result = 0; - String tmp = String.valueOf(octal); - int count = 0; - int multiple; - String caracter; - for (int i = tmp.length(); i > 0; i--) { - caracter = tmp.substring(i-1, i); - multiple = (int) Math.pow(BASE_8, count); - int value = (Integer.parseInt(caracter) * multiple); - count = count + 1; - result += value; - - } - - return String.valueOf(result); - } - -} diff --git a/Odd or Even Game/.idea/Odd or Even Game.iml b/Odd or Even Game/.idea/Odd or Even Game.iml deleted file mode 100644 index 68d86b9..0000000 --- a/Odd or Even Game/.idea/Odd or Even Game.iml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/Odd or Even Game/.idea/misc.xml b/Odd or Even Game/.idea/misc.xml deleted file mode 100644 index 191aa28..0000000 --- a/Odd or Even Game/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/Odd or Even Game/.idea/modules.xml b/Odd or Even Game/.idea/modules.xml deleted file mode 100644 index 88a00c5..0000000 --- a/Odd or Even Game/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/Odd or Even Game/.idea/vcs.xml b/Odd or Even Game/.idea/vcs.xml deleted file mode 100644 index 6c0b863..0000000 --- a/Odd or Even Game/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Odd or Even Game/.idea/workspace.xml b/Odd or Even Game/.idea/workspace.xml deleted file mode 100644 index 1a68506..0000000 --- a/Odd or Even Game/.idea/workspace.xml +++ /dev/null @@ -1,182 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -