CHARCOUN problem

Hi…COULD SOMEONE PLEASE SOLVE AND EXPLAIN THIS QUESTION TO ME

[I haven’t written a full code yet, though i have tried 4-6 time]
I used swapcase() first, then chr(ord( … ) +/- , etc…

Could you help me out @carre @galencolin @ssrivastava990

  1. Convert lowercase to uppercase and vice versa by subtracting or adding 32 to the ASCII value respectively.

  2. Right-shift the lowercases by considering a-z numbered from 0-25. Do the right-shift as (value+R)%26

  3. Left-shift the uppercases by considering A-Z as 0-25 . Do the left-shift as (value-L+26)%26

  4. Print the frequency of every letter in the new string, lowercases and uppercases separately.

1 Like

thanks, but what is wrong if i use swapcase() function (PYTH 3.6)?
Also, i used various methods for counting like set() + count() and dict.get() but they all come in curvy bracket thingys ( ‘{ }’ ) while the required output does not

Did you write a code? It would be much help

I’m sorry but I usually code in Java, so I might not be able to code in Python for this … and I’ve just now built up the logic and haven’t coded it yet :slight_smile:

okay no problem…do tell me when you are done tho…thanks :+1:

Also. whats wrong with this approach:

def split(word):
return list(word)

for _ in range(int(input())):
N = int(input())
r,L = map(int , input().split())
S = input()
SS = S.swapcase()
x = split(SS)
for i in range(len(x)):
if(x[i].isupper()):
x[i] = chr(ord(x[i]) - L)
else:
x[i] = chr(ord(x[i]) + r)
listToStr = ' '.join(map(str, x))
print(listToStr)
res = {}

for keys in x: 
	res[keys] = res.get(keys, 0) + 1
#print(str(res))

i am getting the required output’s first line, i.e, kLfGc… but as separate characters and not one single word (k L f G c…)
And my count is coming as {k : ‘2’} instead of k 2

Why the “tutorial” tag?

i clicked it by mistake and was not able to remove it :frowning: :sweat_smile:

fixed

Also, can you format your code so I can run it myself?

def split(word): 
    return list(word)

for _ in range(int(input())):
	N = int(input())
	r,L = map(int , input().split())
	S = input()
	SS = S.swapcase()
	#print(SS)
	x = split(SS)
	for i in range(len(x)):
		if(x[i].isupper()):
			x[i] = chr(ord(x[i]) - L)
		else:
			x[i] = chr(ord(x[i]) + r)
	listToStr = ' '.join(map(str, x)) 
	print(listToStr)  
	res = {} 
  
	for keys in x: 
		res[keys] = res.get(keys, 0) + 1
	#print(str(res))

Well… one issue is that you have x = split(SS) when I guess you want x = SS.split() (which defaults to splitting by spaces)

def split(word):
    return list(word)


for _ in range(int(input())):
    N = int(input())
    r, L = map(int, input().split())
    S = input()
    SS = S.swapcase()
    # print(SS)
    x = split(SS)
    for i in range(len(x)):
        if x[i]==' ':
            continue
        if (x[i].isupper()):
            x[i] = chr(ord(x[i]) - L)
        else:
            x[i] = chr(ord(x[i]) + r)
    listToStr = ''.join(map(str, x))
    print(listToStr)
    res = {}

    for keys in x:
        if keys==' ':
            continue
        res[keys] = res.get(keys, 0) + 1
    for i in res:
        print(i,res[i],end=" ")
    print()

This would give output in desired format.
The checker for this problem seems to be incorrect.

1 Like

thank you…it seems to be working on Command Prompt
Lemme submit it and see

It doesn’t. I’ve checked.

oh…
I noticed that though first line of output is correct, the order of the second line is wrong (according to example test case)… could that be the reason?

1 Like

Yeah maybe…the author must have not used a custom judge to verify that thing. There could be multiple outputs.

1 Like

I just noticed that the example test case prints the count in alphabetical order, while your code prints it according to appearance of character in string

Required output =

G 1 K 1 L 1 M 1 Q 1 R 1 S 1 W 2 c 1 e 1 f 1 k 2 p 1 t 1

Your output =

k 2 e 1 S 1 f 1 Q 1 K 1 L 1 c 1 t 1 G 1 R 1 W 2 p 1 M 1 

^^^ this is not even order of appearance…how would one fix this?

1 Like

It noticed the same now…you may try to print in that particular order (though the statement should have mentioned this thing).

1 Like

AC Sol
you can sort the keys in dictionary and it will print the desired output.

1 Like

could you explain how…I am a not very experienced in coding :sweat_smile: :dizzy_face:

1 Like

oh kk thanks

1 Like