26/03/2023

It's All About Magic! HackerEarth Solution in C++

Recently Oz has found a magical string consisting of the single digit "1". After experimenting on the string, Oz found a weird magical property of the string that is whenever he touches the string then each digit "1" of the string changed to the digit "0" and each digit "0" of the string changed to "01". Oz found this property interesting and immediately asked a question to RK: "How many 1's and 0's will be in the magical string if he touches the string M times ?"

Input:
 
The first line contains the number of test cases T. Each test case consists of a positive integer - M.

Output:
 
For each test case output two space-separated integers, the number of 1's and number of 0's in the magical string if Oz
touches the string M times.

Constraints:
 
1<= T <=20
1<= M <=90

Sample Input (Plaintext Link)
 
2
1
2
 
Sample Output (Plaintext Link)
 
0 1
1 1

Submit your solution here: Click here

It's All About Magic! HackerEarth Solution in C++


#include <iostream>
using namespace std;
int main()
{
	int t = 0, m = 1, n, i, j, t1;
	int a1 = 1, a2 = 1;

	cout << "Enter the no of times Sample Input\n\n";
	cin >> n;
	cout << t << "  " << m << endl;
	for (i = 0; i < n; i++)
	{
		cout << a1 << "  " << a2 << endl;
		t1 = a1;
		a1 = a2;
		a2 = a2 + t1;
	}
}

The Output of It's All About Magic! HackerEarth Solution


The Output of It's All About Magic! HackerEarth Solution

Similar to It's All About Magic!


Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: