Skip to content

Commit

Permalink
AC
Browse files Browse the repository at this point in the history
  • Loading branch information
dungnguyen-art committed Sep 2, 2021
1 parent ada2b29 commit 26e0bca
Show file tree
Hide file tree
Showing 24 changed files with 370 additions and 27 deletions.
10 changes: 0 additions & 10 deletions Check_Odd_Even.py

This file was deleted.

17 changes: 0 additions & 17 deletions Decode.py

This file was deleted.

21 changes: 21 additions & 0 deletions Decode_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
T = int(input())
while T > 0:
s = ""
st = str(input())
cnt = 1
k = len(st)
for i in range(0,k-1,1):
if st[i] == st[i+1]:
cnt = cnt+1
else:
sTmp = str(cnt) + st[i]
s = s+sTmp
cnt = 1
if st[k-1] != st[k-2]:
sTmp = '1' + st[k-1]
s = s+sTmp
else:
sTmp = str(cnt) + st[k-1]
s= s+sTmp
print(s)
T = T - 1
23 changes: 23 additions & 0 deletions Even_Odd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
T = int(input())
while T>0:
str = input()
sum = 0
check = 1
# t = abs(int(str[0]) - int(str[1]))
# print(type(t))
for index in range(len(str)-1):
if abs(int(str[index]) - int(str[index+1])) == 2:
sum = sum + int(str[index])
else:
check = 0
break
if(check == 0):
print("NO")
else:
sum = sum + int(str[len(str)-1])
if sum % 10 == 0:
print("YES")
else:
print("NO")
# print(sum)
T = T-1
12 changes: 12 additions & 0 deletions First_Last.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -------------------------------------
# create by: Nguyen Tien Dung -
# Date: 11:20 PM 31/8/2021 -
# -------------------------------------
T = int(input())
while T > 0:
str = input()
if str[0] == str[len(str)-2] and str[1] == str[len(str)-1]:
print("YES")
else:
print("NO")
T = T - 1
9 changes: 9 additions & 0 deletions Insert_Comma.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# for i in range(5,-1,-1):
# print(i)
# systax
# str = str1[:index] + str2 + str1[index:]
str = input()
# print(len(str))
for i in range(len(str)-3,0,-3):
str = str[:i] + "," + str[i:]
print(str)
7 changes: 7 additions & 0 deletions Insert_String.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
str1 = input()
str2 = input()
index = int(input())
index = index-1
# def insert_sequence(str1, str2, index):
str = str1[:index] + str2 + str1[index:]
print(str)
25 changes: 25 additions & 0 deletions Inversion_Pair.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# create by: Nguyen Tien Dung -
# Date: 10:35 PM 31/8/2021 -
# -------------------------------------
# import array as arr
#
# a = arr.array('i', [])
#
# k = int(input("Enter size of array:"))
# for i in range(0, k):
# num = int(input())
# a.append(num)
# cnt = 0
# for i in range(0,k-1):
# for j in range(i,k):
# if a[i] > a[j]:
# cnt = cnt + 1
# print(cnt)
T = int(input())
str = [int(x) for x in input().split()]
cnt = 0
for i in range(len(str)-1):
for j in range(i+1,len(str)):
if int(str[i]) > int(str[j]):
cnt = cnt + 1
print(cnt)
13 changes: 13 additions & 0 deletions Lucky_Number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -------------------------------------
# create by: Nguyen Tien Dung -
# Date: 11:24 PM 30/8/2021 -
# -------------------------------------
T = int(input())
while T>0:
str = input()
k = len(str)
if(str[k-1] == '6' and str[k-2] == '8'):
print("YES")
else:
print("NO")
T = T-1
9 changes: 9 additions & 0 deletions Lucky_Number_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
str = input()
cnt = 0
for i in range(len(str)):
if str[i] == '4' or str[i] == '7':
cnt = cnt+1
if cnt == 4 or cnt == 7:
print("YES")
else:
print("NO")
13 changes: 13 additions & 0 deletions Lucky_Number_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
T = int(input())
while T>0:
check = 0
str = input()
for i in range(len(str)):
if str[i] != '4' and str[i] != '7':
check = 1
break
if check == 0:
print("YES")
else:
print("NO")
T = T - 1
18 changes: 18 additions & 0 deletions Matching_Number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
T = int(input())
while T>0:
n = int(input())
str1 = [int(x) for x in input().split()]
str2 = [int(x) for x in input().split()]
str1.sort()
str2.sort()
check = 0
for i in range(0,n,1):
if str1[i] > str2[i]:
check = 1
break

if check == 1:
print("NO")
else:
print("YES")
T = T - 1
33 changes: 33 additions & 0 deletions MostFrequent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# T = int(input())
# while T > 0:
# n = int(input())
# str = input()
# str = str.replace(" ","")
# maxi = 0
# for i in range(0,len(str),1):
# d[str[i]] = d[str[i]] + 1
# if d[str[i]] > maxi:
# maxi = d[str[i]]
# T = T - 1
# print(maxi)
# TLE
T = int(input())
while T>0:
n = int(input())
str = input()
str = str.split()
list_1 = []
list_1[:0] = str
dict = {}
count,itm = 0,''
for item in reversed(list_1):
dict[item] = dict.get(item,0)+1
if dict[item] >= count:
count,itm = dict[item],item

k = list_1.count(itm)
if k > len(str)//2:
print(itm)
else:
print("NO")
T = T - 1
18 changes: 18 additions & 0 deletions No_Decrease.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -------------------------------------
# create by: Nguyen Tien Dung -
# Date: 10:30 PM 30/8/2021 -
# -------------------------------------
T = int(input())
while T>0:
str = input()
check = 0
for index in range(len(str)-1):
if int(str[index]) > int(str[index+1]):
check = 1
break
if check == 0:
print("YES")
else:
print("NO")
T = T-1
print("\n")
16 changes: 16 additions & 0 deletions Prime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import math

T = int(input())

while T>0:
n = int(input())
check = 0
for i in range(2,int(math.sqrt(n))+1,1):
if n%i == 0:
check = 1
break
if check == 0:
print("YES")
else:
print("NO")
T = T - 1
34 changes: 34 additions & 0 deletions Prime_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import math

def Sieve(h):
prime = [True for x in range(h + 1)]
p = 2
while p * p <= h:
if prime[p]:
for j in range(p * p, h + 1, p):
prime[j] = False
p += 1
prime[0] = False
prime[1] = False
cnt = 0
for j in range(2, h + 1):
if prime[j]:
cnt += 1
return cnt
#hello bebe
T = int(input())
while T > 0:
n = int(input())
k = Sieve(n)
flag = True
if k < 2:
flag = False
for i in range(2, int(math.sqrt(k)) + 1, 1):
if k % i == 0:
flag = False
break
if flag:
print("YES")
else:
print("NO")
T -= 1
18 changes: 18 additions & 0 deletions Sum_Number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
T = int(input())
while T>0:
s = input()
n = len(s)
sum = 0
s1 = ""
for i in range(n):
if s[i].isnumeric() == True:
sum += int(s[i])
for i in range(n):
if s[i].isnumeric() != False:
continue
else:
s1 = s1 + s[i]
s2 = sorted(s1)
s1 = "".join(s2)
print(s1+str(sum))
T -= 1
10 changes: 10 additions & 0 deletions Summation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -------------------------------------
# create by: Nguyen Tien Dung -
# Date: 10:23 PM 30/8/2021 -
# ------------------------------------
str = input()
if int(str[0]) + int(str[4]) == int(str[8]):
print("YES")
else:
print("NO")

4 changes: 4 additions & 0 deletions Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ar = [int(x) for x in input().split()]
n = len(ar)
for i in range(n):
print(i)
38 changes: 38 additions & 0 deletions Transform_Number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
k = 10
while k > 0:
ar = [int(x) for x in input().split()]
n = len(ar)
ch = True
for i in range(n):
if ar[i] != 0:
ch = False
if ch == True:
break
cnt = 0
t = 5
check = 0
while t>0:
x = ar[0]
for i in range(n-1):
ar[i] = abs(ar[i] - ar[i+1])

ar[n-1] = abs(ar[n-1] - x)
cnt += 1
ok = True
for i in range(n):
if ar[i] != 0:
ok = False
break
if ok == True:
t = 0
# print(cnt)
print(cnt-1)

# //1 3 5 9
# //2 2 4 8
# //0 2 4 6
# //2 2 2 6
# //0 0 4 4
# //0 4 0 4
# //4 4 4 4
# //0 0 0 0
17 changes: 17 additions & 0 deletions Upper_Lower.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -------------------------------------
# create by: Nguyen Tien Dung -
# Date: 11:42 PM 30/8/2021 -
# -------------------------------------
str = input()
up,lo = 0,0
for index in range(len(str)):
if str[index] >= 'a':
lo = lo + 1
else:
up = up + 1
if up > lo:
print(str.upper())
elif lo >= up:
print(str.lower())


Loading

0 comments on commit 26e0bca

Please sign in to comment.