Hãy luôn nhớ cảm ơn và vote 5*
nếu câu trả lời hữu ích nhé!
`*` Số chính phương lớn nhất trong mảng
$\texttt{C++}$
#include <bits/stdc++.h>
using namespace std;
bool check(long long a)
{
long long k = sqrt(a);
return k * k == a;
}
int main()
{
long long n, res = -1, a;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a;
if (check(a))
res = max(res, a);
}
cout << res;
return 0;
}
`*` Tổng chữ số(phiên bản số nguyên)
$\texttt{C++}$
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin >> s;
cout << accumulate(s.begin(), s.end(), 0) - '0' * s.size();
return 0;
}
`*` Tổng chữ số của hai số nguyên
$\texttt{C++}$
#include <bits/stdc++.h>
using namespace std;
int tcs(long long n)
{
int res = 0;
while (n != 0)
{
res += n % 10;
n /= 10;
}
return res;
}
int main()
{
long long a, b;
cin >> a >> b;
cout << tcs(a) + tcs(b);
return 0;
}
Hãy giúp mọi người biết câu trả lời này thế nào?
\begin{array}{c} \color{#db1616}{\texttt{#Khoadang09}} \end{array}
*Số chính phương :
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
using namespace std;
bool scp(ll n){
ll srt = sqrt(n);
return n == srt * srt;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n; cin >> n;
vector <ll> a(n);
for (ll&i:a) cin >> i;
ll maxscp = -1;
for (ll i:a) if (scp(i)) maxscp = max(maxscp,i);
cout << maxscp;
return 0;
}
*Tổng chữ số :
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
ll n; cin >> n;
int s = 0;
while (n!=0){
s += n % 10;
n /= 10;
}
cout << s;
return 0;
}
*Tổng chữ số 2 số nguyên :
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
ll a, b; cin >> a >> b;
int s = 0;
while (a!=0||b!=0){
s += a % 10; s += b % 10;
a /= 10; b /=10 ;
}
cout << s;
return 0;
}
Hãy giúp mọi người biết câu trả lời này thế nào?
Bảng tin
5599
4388
3494
AC k bro, cap mn xem
2707
41698
2038
:)) Tenshi - sama, trên bảng submissions ấy, lười chụp
5599
4388
3494
chéo thg kia == m tàn tác lắm
2707
41698
2038
=)) Vote cho lawms zoo
5599
4388
3494
đc mod vote tht vinh hạnh
2707
41698
2038
Mod nào, a sham á :v