From f05d888a0b621ca4e99e2b0fb6e23c097006fe41 Mon Sep 17 00:00:00 2001 From: Santo Cariotti <santo@dcariotti.me> Date: Tue, 28 May 2024 10:29:13 +0200 Subject: Init --- progs/a381.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 progs/a381.py (limited to 'progs/a381.py') diff --git a/progs/a381.py b/progs/a381.py new file mode 100644 index 0000000..40a9fae --- /dev/null +++ b/progs/a381.py @@ -0,0 +1,26 @@ +NO_OF_CHARS = 256 +def str_to_list(string): + temp = [] + for x in string: + temp.append(x) + return temp +def lst_to_string(List): + return ''.join(List) +def get_char_count_array(string): + count = [0] * NO_OF_CHARS + for i in string: + count[ord(i)] += 1 + return count +def remove_dirty_chars(string, second_string): + count = get_char_count_array(second_string) + ip_ind = 0 + res_ind = 0 + temp = '' + str_list = str_to_list(string) + while ip_ind != len(str_list): + temp = str_list[ip_ind] + if count[ord(temp)] == 0: + str_list[res_ind] = str_list[ip_ind] + res_ind += 1 + ip_ind+=1 + return lst_to_string(str_list[0:res_ind]) \ No newline at end of file -- cgit v1.2.3-18-g5258