A. Love Story
Solution
Given that the length of the provided string is 10, the approach involves iterating through the string and comparing each character at position i with the corresponding character at position i in "codeforces."
Code
t = int(input())
c = "codeforces"
for _ in range(t):
s = input()
res = 0
for i in range(10):
if s[i] != c[i]:
res += 1
print(res)
D. Same Differences
Hint 1
Can you rewrite the formula?
Solution
The equation $$$a_j - a_i = j - i$$$ can be transformed into $$$a_j - j = a_i - i$$$, and let $$$b_i = a_i - i$$$. Then we need to count the number of pairs $$$(i, j)$$$ where $$$b_i = b_j$$$. We can use a dictionary(hash map) to count occurrences of each difference $$$(b_i)$$$.
Code
T = int(input())
for _ in range(T):
N = int(input())
a = list(map(int,input().split()))
difference_count = {}
pair_count = 0
for i in range(N):
difference = a[i] - i
pair_count += difference_count.get(difference, 0)
difference_count[difference] = difference_count.get(difference, 0) + 1
print(pair_count)