Skip to main content

Posts

Showing posts with the label Data Structures

URI Problem 1259 Solution Even and Odd - URI Online Judge Solution

URI Online Judge Solution 1259 Even and Odd  Using C++, Python Programming Language. Considering the input of non-negative integer values​​, sort these numbers ​​according to the following criteria: First the even in ascending order followed by the odd in descending order. Input The first line of input contains a positive integer number N (1 < N < 105). This is the number of following input lines. The next N lines contain, each one, a integer non-negative number. Output Print all numbers according to the explanation presented above. Each number must be printed in one line as shown below. Sample Input Sample Output 10 4 32 34 543 3456 654 567 87 6789 98 4 32 34 98 654 3456 6789 567 543 87 Solution Using C++: #include<iostream> #include<algorithm> using namespace std; int main() { int i , n; cin>>n; int arr[n]; for (i= 0 ; i<n; i++) { cin>>arr[i]; } sort(arr , arr+n); for (i= 0 ; i<n; i++) { if (a...

URI Online Judge Solution 1069 Diamonds and Sand

URI Online Judge Solution 1069  Diamonds and Sand using Python Programming Language. John is working in a diamond mine, trying to extract the highest number of diamond "<>". He must exclude all sand particles found "." in this process and after a diamond can be extracted, new diamonds can be formed. If he has as an input. <... << .. >> ....> .... >>>. three diamonds are formed. The first is taken from <..> resulting. <... <> ....> .... >>>. The second diamond is then removed, leaving. <.......> .... >>>. The third diamond is then removed, leaving at the end ..... >>>. without the possibility of extracting new diamonds. Input Read an integer N that is the number of test cases. Then follows N lines each up to 1000 characters, including "<" ,">" and "." Output You must print the amount of diamonds that can be extrated in each test ca...

URI Online Judge Solution 1068 Parenthesis Balance I

URI Online Judge Solution 1068 Parenthesis Balance I using Python Programming Language. Considering an expression with parenthesis, print a message informing if the among of parenthesis is correct or incorrect, without considering the rest of the expression. Example: a+(b*c)-2-a         is correct (a+b*(2-c)-2+a)*2   is correct when (a*b-(2+c)          is incorrect 2*(3-a))            is incorrect )3+b*(2-c)(         is incorrect Resuming, all closing parenthesis must have an open parenthesis and it's not possible a closing parenthesis without a previous open parenthesis, and the quantity of closing and open parenthesis must be the same. Input The input file contains  N  expressions (1 <=  N  <= 10000), each one with up to 1000 characters.  Output ...

URI Problem 1025 Solution Where is the Marble? - URI Online Judge Solution

URI Online Judge Solution 1025 Where is the Marble? using Python Programming Language. Raju and Meena love to play with Marbles. They have a lot of marbles with numbers written on them. In the beginning, Raju would place the marbles one after another in ascending order of the numbers written on them. Then, Meena would ask Raju to find the first marble with a certain number. She would count 1...2...3. Raju gets one point for correct answer, and Meena gets the point if Raju fails. After some fixed number of attempts, the game ends and the player with maximum points wins. Today it's your chance to play as Raju. Being a smart kid, you have in your advantage the computer. But don't underestimate Meena, she wrote a program to keep track how much time you're taking to give all the answers. So now you have to write a program, which will help you in your role as Raju. Input There can be multiple test cases. The total number of test cases is less than 65. Each test case c...

URI Problem 1022 Solution TDA Rational - URI Online Judge Solution

URI Online Judge Solution 1022 TDA Rational using Python Programming Language. You were invited to do a little job for your Mathematic teacher. The job is to read a Mathematic expression in format of two rational numbers (numerator / denominator) and present the result of the operation. Each operand or operator is separated by a blank space. The input sequence (each line) must respect the following format: number, (‘/’ char), number, operation char (‘/’, ‘*’, ‘+’, ‘-‘), number, (‘/’ char), number. The answer must be presented followed by ‘=’ operator and the simplified answer. If the answer can’t be simplified, it must be repeated after a ‘=’ operator. Considering N1 and D1 as numerator and denominator of the first fraction, follow the orientation about how to do each one of these 4 operations: Sum: (N1*D2 + N2*D1) / (D1*D2) Subtraction: (N1*D2 - N2*D1) / (D1*D2) Multiplication: (N1*N2) / (D1*D2) Division: (N1/D1) / (N2/D2), that means (N1*D2)/(N2*D1) Input The input contains sev...