Hãy luôn nhớ cảm ơn và vote 5*
nếu câu trả lời hữu ích nhé!
\begin{array}{c} \color{#db1616}{\texttt{#Khoadang09}} \end{array}
*Bài 1, C1:
- s.isupper() : nếu chuỗi/ ký tự toàn ký tự in hoa, trả về True, ngược lại trả về False
- s.islower() : nếu chuỗi/ ký tự toàn ký tự in thường, trả về True, ngược lại trả về False
- s.isdigit() : nếu chuỗi/ ký tự toàn ký tự số, trả về True, ngược lại trả về False
$\texttt{*Code :}$
n = input()
d_inhoa = d_inth = d_so = 0
for i in n :
if i.isupper() :
d_inhoa += 1
elif i.islower() :
d_inth += 1
elif i.isdigit() :
d_so += 1
print(d_inhoa)
print(d_inth)
print(d_so)
*Bài 1, C2:
- Nhìn vào bảng Asscii, ta có nhận xét :
+ Vị trí các chữ số : 48 → 57
+ Vị trí các chữ in hoa : 65 → 90
+ Vị trí các chữ in thường : 97 → 122
- Ta có hàm ord(s) : trả về vị trí của ký tự s trong bảng mã Asscii
⇒ Dùng so sánh vị trí khi kết hợp hàm ord
$\texttt{*Code :}$
n = input()
d_inhoa = d_inth = d_so = 0
for i in n :
if ord(i) >= 65 and ord(i) <= 90 :
d_inhoa += 1
elif ord(i) >= 90 and ord(i) <= 122 :
d_inth += 1
elif ord(i) >= 48 and ord(i) <= 57 :
d_so += 1
print(d_inhoa)
print(d_inth)
print(d_so)
*Bài 2 :
*Dựa vào lượng hàm bài 1 và bổ sung :
- s.isalnum() : nếu chuỗi tồn tại ký tự số hoặc chữ cái, trả về True, ngược lại trả về False
→ "23a".isalnun() : True
→ "25347358464".islanum() : True
→ "i hate u ==".isalnum() : False
⇒ Dùng phép not đảo giá trị để kiểm tra ký tự đặc biệt
$\texttt{*Code :}$
n = input()
kt_db = kt_hoa = kt_so = kt_th = False
if len(n) <= 6 :
print("Yeu")
else :
for i in n :
# bat dau kt = for
# kt co la ky tu chu cai
if i.isalpha() :
# in hoa ?
if i.isupper() :
kt_hoa = True
# in thuong ?
elif i.islower() :
kt_th = True
# so ?
if i.isdigit() :
kt_so = True
# kt ky tu dac biet
if not i.isalnum() :
kt_db = True
if kt_hoa and kt_th and kt_so and kt_db :
print("Manh")
else :
print("Yeu")
Hãy giúp mọi người biết câu trả lời này thế nào?
Bài 1:
#include<bits/stdc++.h>
#define int long long
using namespace std;
string s;
int hoa=0, thuong=0, so=0;
signed main()
{
getline(cin,s);
for (int i=0; i<s.size(); i++)
{
if (s[i]>='A'&&s[i]<='Z') hoa++;
if (s[i]>='a'&&s[i]<='z') thuong++;
if (s[i]>='0'&&s[i]<='9') so++;
}
cout << "So ki tu chu hoa la: " << hoa << "\n" << "So ki tu chu thuong la: " << thuong << "\n" << "So ki tu so la: " << so;
}
Bài 2:
#include<bits/stdc++.h>
#define int long long
using namespace std;
string s;
int d=0;
signed main()
{
getline(cin,s);
for (int i=0; i<s.size(); i++)
{
if (s[i]>='A'&&s[i]<='Z') d++;
break;
if (s[i]>='a'&&s[i]<='z') d++;
break;
if (s[i]>='0'&&s[i]<='9') d++;
break;
if (s[i]=='!' or s[i]=='@' or s[i]=='#' or s[i]=='$' or s[i]=='%' or s[i]=='^' or s[i]=='&' or s[i]=='*' or s[i]=='(' or s[i]==')') d++;
break;
if (s.size()>6) d++;
}
if (d>=5) cout << "YES";
else cout << "NO";
}
Hãy giúp mọi người biết câu trả lời này thế nào?
Sự kiện