Posts

Showing posts from May, 2021

Jishan's Log 11: Codeforces 112A solution

Codeforces 112A: Petya & Strings What does the problem want? Petya is given two strings. Petya now needs to make sure (regardless of case) the strings are of same length. How to solve it? The Algorithm: 1) Take 2 strings. 2) convert them to lower case 3) compare them  The Code: #include <bits/stdc++.h> using   namespace   std ; #define   fastio   ios :: sync_with_stdio ( 0 );  cin . tie ( 0 );  cout . tie ( 0 ); int   main () {      fastio ;      string   s1 ;  cin   >>   s1 ;      string   s2 ;  cin   >>   s2 ;           for_each ( s1 . begin (),  s1 . end (), []( char   &   c ) {          c   =   tolower ( c );     });      for_each ( s2 . begin (),  s2 . end (),...

Jishan's Log 10: Codeforces 281A solution

Codeforces 281A: Word Capitalization What does the problem want? This problem is simple. Just capitalize the first word of the sentence. That's it! How to solve it? The Algorithm: 1) Take a string 2) Convert the first word to upper. The Code: #include <bits/stdc++.h> using   namespace   std ; #define   fastio   ios :: sync_with_stdio ( 0 );  cin . tie ( 0 );  cout . tie ( 0 ); int   main () {      fastio ;      string   s ;  cin   >>   s ;      s [ 0 ]   =   toupper ( s [ 0 ] );      cout   <<   s   <<   " \n " ;      } 

Jishan's Log 9: Codeforces 399A solution

 Codeforces 399A: Helpful Maths What does the problem want? The problem states that a teacher has written a summation expression on the board and Xenia must solve it. However, Xenia can count in ascending order ONLY and not in any other way. We must arrange the numbers of the expression in ascending order so that Xenia can count them. How to solve it? The Algorithm: 1) Take a string input 2) Take a character array. Iterate through the string and insert the chars in the string into the char array if, and only if the char is not '+'. After that, sort the array and then finally print it. The Code: #include <bits/stdc++.h> using   namespace   std ; #define   fastio   ios :: sync_with_stdio ( 0 );  cin . tie ( 0 );  cout . tie ( 0 ); int   main () {      fastio ;      string   s ;  cin   >>   s ;      char   temp [ s . length ()];  int   n   ...

Jishan's Log 8: Codeforces 263A solution

Codeforces 263A: A Beautiful Matrix What the problem wants? The problem states that a 5x5 matrix is given. It is full of 0's except one position has the number 1. We need to find the minimum moves needed to shift 1 from its current position to the center of the matrix. How to solve it? The Algorithm: 1) take a matrix and its input. 2) search for 1. If found, then find the absolute value from where it is to the center of the matrix. Do this for both i & j position.  ***NOTE: The logic here is that the minimum moves made will only be through the horizontal or vertical movement. not cross movements. So we take the i at that position and subtract it to the i of the center element. Same for j. The Code: #include <bits/stdc++.h> using   namespace   std ; #define   fastio   ios :: sync_with_stdio ( 0 );  cin . tie ( 0 );  cout . tie ( 0 ); void   minMoves ( int   matrix [ 5 ][ 5 ]) {      int   i_idx   = ...

Jishan's Log 7: Codeforces 118A solution

 Codeforces 118A: String Task What the problem wants? This problem deals with strings (as the name suggests). The task is to take the string, and turn it into a format such that there are no vowels (a,e,i,y,o,u) and there are " . " s before the consonants. Example: tour gets turned into => ".t.r". How to solve it? The Algorithm: 1) take string input 2) convert to lower-case 3) Iterate through the string. If the character is a vowel, skip it. Else add . then add the character to another string. The Code: #include <bits/stdc++.h> using   namespace   std ; #define   fastio   ios :: sync_with_stdio ( 0 );  cin . tie ( 0 );  cout . tie ( 0 ); string   StringBuilder ( string   s ) {      string   str   =   "" ;      for_each ( s . begin (),  s . end (), []( char   &   c ) {          c   =   tolower ( c ); ...

Jishan's Log 6: Codeforces 158A solution

 Codeforces 158A: Next Round What the problem wants? The problem states that there are a n scores and from those scores we must take the score of the kth position as the passing mark. If a score is greater than or equal to the kth position and if it is greater than 0, then the candidate passes.  How to solve it? Algorithm: 1) take the n and k inputs 2) for i=0 => n (1 => n), we read the integers and store it in an array. We then get the value of the kth position and check if the value in the array is greater than k or not & if it is greater than 0. If it is, we increment a counter. Finally we print it. The Code: ***NOTE: Since I've taken the array from 0 => n, that's why I've taken the k-1 position. If you start from 1, you can take k only #include <bits/stdc++.h> using   namespace   std ; #define   fastio   ios :: sync_with_stdio ( 0 );  cin . tie ( 0 );  cout . tie ( 0 ); int   main () {      fastio ; ...

Jishan's Log 5: Codeforces 231A solution

 Codeforces 231A: Team What the problem wants? The 3 friends have formed a team and while solving problems, they want to make sure how many are confident about the solution. If 2/3 are confident, then they will implement the solution. Else they will ignore it. How to solve the problem? Algorithm: For variable names, look at the code below: 1) take n tests as input 2) from i = 1 => 3 ( 0 => 2) take an input, and see if it is 1. If it is, then increment the i_counter. Keep checking this for the remaining two. Lastly, check if the i_counter has values >= 2. If yes, increment the sol_counter and finally print it. The Code: #include <bits/stdc++.h> using   namespace   std ; #define   fastio   ios :: sync_with_stdio ( 0 );  cin . tie ( 0 );  cout . tie ( 0 ); int   main () {      fastio ;      int   n ;  scanf ( " %d " ,  & n );      int    sol_count ...

Jishan's Log 4: Codeforces 71A solution

 Codeforces 71A: Way Too Long Words You might've heard of codeforces. If not, let me tell you that they are one of the most challenging online judges in the internet right now. Their problem sets are very unique and will pick your brain a lot. Today, I'll walk you through such a problem. Problem 71A: Way Too Long Words. What the problem wants? The problem basically tells us to take a word and if it is way too long we need to convert it to a shorter form (a guideline which they have given). The author states that any word bigger than 10 is a long word and must be shortened in the way that: the first letter will be its starting letter. The next will be the number of characters present between the starting and ending letter, and finally, the last letter will be its ending letter. Example: initialization i12n There are 12 letter between i and n. The Solution: Algorithm: 1) Take the word input 2) check if it's less than or equal to 10. 3) If yes, simple print the word. 4) Else, ...

Jishan's Log 3: GUI Color Picker

Image
 GUI Color Picker using JAVA SWING Have you heard of RGB color? It's a combination of three colors: Red, Green, and Blue to make a color. A single color's intensity goes from 0 to 255. The more it increases, the more shade of that color is seen. Let's take a brief look at it:                Here, you can see the colors of combinations set by Red, Green, and Blue color. I have developed a GUI application using Java's Swing framework to make such color picker.    The working here is simple. There are three sliders which will change the color of the JPanel whenever scrolled, a button is there named "Get RGB Code" and upon clicking, the color code for all 3 colors between 0-255 are shown.   Here are the codes for it. ColorPicker.java import javax.swing.* ; import java.awt.* ; import java.awt.event.ActionEvent ; import java.awt.event.ActionListener ; import java.awt.event.AdjustmentEvent ; import java.awt.event.AdjustmentListener ; ...

Jishan's Log 2: Caesar's Cipher

Image
                    Welcome!                      I'm currently working on the Caesar's Cipher.             Before showing you what I'm trying to do, let me show you what the cipher actually is.                                    This is the Caesar Cipher:                     This was used by the Romans during the time of Caesar to pass out secret messages                    of the Roman Administration.                     It works by taking a letter and a SECRET KEY (any number) and we move from the              ...

Jishan's Log 1: Welcome!

Image
                 Welcome to Log 1: Here, I will write about technical stuff and non-technical stuff and hot tech topics. Stay tuned, and hopefully even I'll stay tuned!