Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4acf097

Browse files
committed
special21 -day1
1 parentb08db0e commit4acf097

File tree

3 files changed

+94
-108
lines changed

3 files changed

+94
-108
lines changed

‎geeksforgeeks/.ipynb_checkpoints/must_do_coding_questions-checkpoint.ipynb

Lines changed: 0 additions & 108 deletions
This file was deleted.

‎geeksforgeeks/special21/M_and_N.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// https://practice.geeksforgeeks.org/contest-problem/m-and-n5047
2+
3+
#include<bits/stdc++.h>
4+
usingnamespacestd;
5+
6+
// ver 1
7+
voidsolution(int M,int N)
8+
{
9+
string m_n =to_string(M+N);
10+
string n =to_string(N);
11+
if (n.size() == m_n.size())
12+
{
13+
cout << N;
14+
}
15+
else
16+
{
17+
cout << m_n;
18+
}
19+
cout <<'\n';
20+
}
21+
22+
23+
// ver 2
24+
intcountdigit(longlongint no)
25+
{
26+
int count=0;
27+
while (no!=0)
28+
{
29+
count++;
30+
no /=10;
31+
}
32+
return count;
33+
}
34+
35+
intsolution2(int M,int N)
36+
{
37+
int m_n = M + N;
38+
39+
if (countdigit(N) ==countdigit(m_n))
40+
return N;
41+
else
42+
return m_n;
43+
}
44+
45+
46+
47+
48+
intmain()
49+
{
50+
ios::sync_with_stdio(0);
51+
cin.tie(0);
52+
int T, M, N;
53+
cin >> T;
54+
while (T--)
55+
{
56+
cin >> M >> N;
57+
solution(M, N);
58+
}
59+
60+
return0;
61+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// https://practice.geeksforgeeks.org/contest-problem/triangle-and-square
2+
3+
#include<bits/stdc++.h>
4+
usingnamespacestd;
5+
6+
// ver 1
7+
voidsolution(int b)
8+
{
9+
// count num of squares
10+
int n = (b-2)/2;
11+
int num_squares = n;
12+
while (n--)
13+
{
14+
num_squares += n;
15+
}
16+
cout << num_squares <<'\n';
17+
}
18+
19+
20+
intmain()
21+
{
22+
ios::sync_with_stdio(0);
23+
cin.tie(0);
24+
int T, B;
25+
cin >> T;
26+
while (T--)
27+
{
28+
cin >> B;
29+
solution(B);
30+
}
31+
32+
return0;
33+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp