We are back on our track after facing a lot of obstacles and here I am providing you two more example questions based on strings and some basic concepts of mathematics.
LUCKY FOUR
Prerequisites :: Basic knowledge of Strings
Kostya likes the number 4 much. Of course! This number has such a lot of properties, like:
- Four is the smallest composite number;
- It is also the smallest Smith number;
- The smallest non-cyclic group has four elements;
- Four is the maximal degree of the equation that can be solved in radicals;
- There is four-color theorem that states that any map can be colored in no more than four colors in such a way that no two adjacent regions are colored in the same color;
- Lagrange’s four-square theorem states that every positive integer can be written as the sum of at most four square numbers;
- Four is the maximum number of dimensions of a real division algebra;
- In bases 6 and 12, 4 is a 1-automorphic number;
And there are a lot more cool stuff about this number!
Impressed by the power of this number, Kostya has begun to look for occurrences of four anywhere. He has a list of T integers, for each of them he wants to calculate the number of occurrences of the digit 4 in the decimal representation. He is too busy now, so please help him.
Input
The first line of input consists of a single integer T, denoting the number of integers in Kostya’s list.
Then, there are T lines, each of them contain a single integer from the list.
Output
Output T lines. Each of these lines should contain the number of occurences of the digit 4 in the respective integer from Kostya’s list.
Constraints
1 ≤ T ≤ 105
(Subtask 1): 0 ≤ Numbers from the list ≤ 9 – 33 points.
(Subtask 2): 0 ≤ Numbers from the list ≤ 109 – 67 points.
Example::
Input:
5
447474
228
6664
40
81
Output:
4
0
1
1
0
Submission link for LUCKY FOUR :: https://www.codechef.com/submit/LUCKFOUR
RECTANGLE
Prerequisites : Basic Mathematics
You are given four integers a, b, c and d. Determine if there’s a rectangle such that the lengths of its sides are a, b, c and d (in any order).
Input:
The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
The first and only line of each test case contains four space-separated integers a, b, c and d.
Output:
For each test case, print a single line containing one string “YES” or “NO”.
Constraints
1 ≤ T ≤ 1,000
1 ≤ a, b, c, d ≤ 10,000
Subtask #1 (100 points): original constraints
Example::
Input:
3
1 1 2 2
3 2 2 3
1 2 2 2
Output:
YES
YES
NO
Submission link for RECTANGLE:: https://www.codechef.com/submit/RECTANGL
Try, try and try, again and again until you solve these two cute problems.
Doesn’t matter how much time it will take, 1 hour/ 10 hours or a day. But you should keep trying. Brainstorming and continuously working hard is the only Måńțřå for enhancing the coding skills.
Check the solutions only after you tried as much possible for you. 🤗
Solution for Lucky Four ::
using namespace std;
int main()
{
long int t,n;
string str;
cin>>t;
while(t–)
{
int count=0,i;
cin>>str;
for(i=0;i<str.length();i++)
{
if(str[i]==’4′)
count++;
}
cout<<count;
}
}
Solution for Rectangle ::
using namespace std;
int main()
{
int t,a,b,c,d;
cin>>t;
while(t–)
{
cin>>a>>b>>c>>d;
if((a==b && c==d) || (a==c && b==d )||(a==d && b==c))
{
cout<<“YES”;
}
else
cout<<“NO”;
}
return 0;
}
Back soon🙋🏻♀️🤗🤗
In order to post the code on the page, you should use pre tag then it will keep your code’s indentation so it will be easy to read ; )
LikeLike