| 模型 | 模型答案 | 正确答案 |
|---|---|---|
| 金声玉亮2.0 | ```python import sys input = sys.stdin.read data = input().split() N = int(data[0]) S = list(data[1]) Q = int(data[2]) for i in range(Q): c, d = data[3 + 2 * i], data[4 + 2 * i] S = [d if char == c else char for char in S] print(''.join(S)) ``` |
[{"input": "7\natcoder\n4\nr a\nt e\nd v\na r\n", "output": "recover\n", "testtype": "stdin"}, {"input": "3\nabc\n4\na a\ns k\nn n\nz b\n", "output": "abc\n", "testtype": "stdin"}, {"input": "34\nsupercalifragilisticexpialidocious\n20\ng c\nl g\ng m\nc m\nr o\ns e\na a\no f\nf s\ne t\nt l\nd v\np k\nv h\nx i\nh n\nn j\ni r\ns i\nu a\n", "output": "laklimamriiamrmrllrmlrkramrjimrial\n", "testtype": "stdin"}] |
| deepseek-r1 | ```python def main(): import sys input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr += 1 S = input[ptr] ptr += 1 Q = int(input[ptr]) ptr += 1 # Initialize substitution map: each character maps to itself initially m = list(range(26)) for _ in range(Q): c = input[ptr] d = input[ptr + 1] ptr += 2 cc = ord(c) - ord('a') dc = ord(d) - ord('a') # Update all characters that currently map to cc to map to dc for i in range(26): if m[i] == cc: m[i] = dc # Build the result string res = [] for char in S: idx = ord(char) - ord('a') res.append(chr(m[idx] + ord('a'))) print(''.join(res)) if __name__ == '__main__': main() ``` |
[{"input": "7\natcoder\n4\nr a\nt e\nd v\na r\n", "output": "recover\n", "testtype": "stdin"}, {"input": "3\nabc\n4\na a\ns k\nn n\nz b\n", "output": "abc\n", "testtype": "stdin"}, {"input": "34\nsupercalifragilisticexpialidocious\n20\ng c\nl g\ng m\nc m\nr o\ns e\na a\no f\nf s\ne t\nt l\nd v\np k\nv h\nx i\nh n\nn j\ni r\ns i\nu a\n", "output": "laklimamriiamrmrllrmlrkramrjimrial\n", "testtype": "stdin"}] |
| gpto1 | ```python # YOUR CODE HERE import sys import threading def main(): import sys import bisect sys.setrecursionlimit(1 << 25) input = sys.stdin.readline N = int(sys.stdin.readline()) S = sys.stdin.readline().strip() Q = int(sys.stdin.readline()) operations = [] for _ in range(Q): c_i, d_i = sys.stdin.readline().strip().split() operations.append((c_i, d_i)) mapping = {chr(ord('a') + i): chr(ord('a') + i) for i in range(26)} for c_i, d_i in reversed(operations): mapping[c_i] = mapping[d_i] result = ''.join(mapping[c] for c in S) print(result) threading.Thread(target=main).start() ``` |
[{"input": "7\natcoder\n4\nr a\nt e\nd v\na r\n", "output": "recover\n", "testtype": "stdin"}, {"input": "3\nabc\n4\na a\ns k\nn n\nz b\n", "output": "abc\n", "testtype": "stdin"}, {"input": "34\nsupercalifragilisticexpialidocious\n20\ng c\nl g\ng m\nc m\nr o\ns e\na a\no f\nf s\ne t\nt l\nd v\np k\nv h\nx i\nh n\nn j\ni r\ns i\nu a\n", "output": "laklimamriiamrmrllrmlrkramrjimrial\n", "testtype": "stdin"}] |
| gpt-4o-2024-08-06 | ```python # YOUR CODE HERE import sys input = sys.stdin.read def main(): data = input().split() N = int(data[0]) S = data[1] Q = int(data[2]) operations = data[3:] # Create a mapping of characters to their final replacements replacement_map = {} for i in range(Q): c_i = operations[2 * i] d_i = operations[2 * i + 1] # If c_i is already mapped to something, we need to update the mapping # to reflect the new replacement if c_i in replacement_map: # Update the mapping for all characters that map to c_i for key in list(replacement_map.keys()): if replacement_map[key] == c_i: replacement_map[key] = d_i # Also update c_i itself replacement_map[c_i] = d_i else: # Directly map c_i to d_i replacement_map[c_i] = d_i # Now apply the final replacement map to the string S result = [] for char in S: if char in replacement_map: result.append(replacement_map[char]) else: result.append(char) print(''.join(result)) main() ``` |
[{"input": "7\natcoder\n4\nr a\nt e\nd v\na r\n", "output": "recover\n", "testtype": "stdin"}, {"input": "3\nabc\n4\na a\ns k\nn n\nz b\n", "output": "abc\n", "testtype": "stdin"}, {"input": "34\nsupercalifragilisticexpialidocious\n20\ng c\nl g\ng m\nc m\nr o\ns e\na a\no f\nf s\ne t\nt l\nd v\np k\nv h\nx i\nh n\nn j\ni r\ns i\nu a\n", "output": "laklimamriiamrmrllrmlrkramrjimrial\n", "testtype": "stdin"}] |
| DeepSeek-Coder-V2-Lite-Instruct | ```python # YOUR CODE HERE import sys # Read input N = int(input()) S = input() Q = int(input()) # Initialize the string as a list to allow modifications S_list = list(S) # Perform the operations for _ in range(Q): c_i, d_i = input().split() for i in range(N): if S_list[i] == c_i: S_list[i] = d_i # Convert the list back to a string and print it print(''.join(S_list)) ``` |
[{"input": "7\natcoder\n4\nr a\nt e\nd v\na r\n", "output": "recover\n", "testtype": "stdin"}, {"input": "3\nabc\n4\na a\ns k\nn n\nz b\n", "output": "abc\n", "testtype": "stdin"}, {"input": "34\nsupercalifragilisticexpialidocious\n20\ng c\nl g\ng m\nc m\nr o\ns e\na a\no f\nf s\ne t\nt l\nd v\np k\nv h\nx i\nh n\nn j\ni r\ns i\nu a\n", "output": "laklimamriiamrmrllrmlrkramrjimrial\n", "testtype": "stdin"}] |
| Meta-Llama-3.1-405B-Instruct-Turbo | ```python import sys def solve(): n = int(input()) s = input() q = int(input()) mp = {} for i in range(q): c, d = input().split() mp[c] = d for i in range(26): c = chr(ord('a') + i) d = c while d in mp: d = mp[d] mp[c] = d ans = [] for c in s: ans.append(mp[c]) print(''.join(ans)) if __name__ == '__main__': solve() ``` |
[{"input": "7\natcoder\n4\nr a\nt e\nd v\na r\n", "output": "recover\n", "testtype": "stdin"}, {"input": "3\nabc\n4\na a\ns k\nn n\nz b\n", "output": "abc\n", "testtype": "stdin"}, {"input": "34\nsupercalifragilisticexpialidocious\n20\ng c\nl g\ng m\nc m\nr o\ns e\na a\no f\nf s\ne t\nt l\nd v\np k\nv h\nx i\nh n\nn j\ni r\ns i\nu a\n", "output": "laklimamriiamrmrllrmlrkramrjimrial\n", "testtype": "stdin"}] |
| Meta-Llama-3.1-70B-Instruct-Turbo | ```python import sys def solve(): n = int(input()) s = input() q = int(input()) queries = [input().split() for _ in range(q)] mapping = {} for c, d in queries: if c in mapping: mapping[d] = mapping[c] else: mapping[d] = d mapping[c] = d result = [] for char in s: while char in mapping: char = mapping[char] result.append(char) print(''.join(result)) if __name__ == '__main__': solve() ``` |
[{"input": "7\natcoder\n4\nr a\nt e\nd v\na r\n", "output": "recover\n", "testtype": "stdin"}, {"input": "3\nabc\n4\na a\ns k\nn n\nz b\n", "output": "abc\n", "testtype": "stdin"}, {"input": "34\nsupercalifragilisticexpialidocious\n20\ng c\nl g\ng m\nc m\nr o\ns e\na a\no f\nf s\ne t\nt l\nd v\np k\nv h\nx i\nh n\nn j\ni r\ns i\nu a\n", "output": "laklimamriiamrmrllrmlrkramrjimrial\n", "testtype": "stdin"}] |
| Qwen2-72B-Instruct | ```python n = int(input()) s = list(input()) q = int(input()) operations = [input().split() for _ in range(q)] replacements = {} for c, d in reversed(operations): if c in replacements: replacements[c] = d else: replacements[c] = d for i in range(n): if s[i] in replacements: s[i] = replacements[s[i]] print("".join(s)) ``` ``` |
[{"input": "7\natcoder\n4\nr a\nt e\nd v\na r\n", "output": "recover\n", "testtype": "stdin"}, {"input": "3\nabc\n4\na a\ns k\nn n\nz b\n", "output": "abc\n", "testtype": "stdin"}, {"input": "34\nsupercalifragilisticexpialidocious\n20\ng c\nl g\ng m\nc m\nr o\ns e\na a\no f\nf s\ne t\nt l\nd v\np k\nv h\nx i\nh n\nn j\ni r\ns i\nu a\n", "output": "laklimamriiamrmrllrmlrkramrjimrial\n", "testtype": "stdin"}] |
| baichuan4 | ```python # YOUR CODE HERE import sys # Read input values N = int(sys.stdin.readline().strip()) S = sys.stdin.readline().strip() Q = int(sys.stdin.readline().strip()) # Perform the operations for _ in range(Q): c_i, d_i = sys.stdin.readline().strip().split() S = S.replace(c_i, d_i) # Print the final string print(S) ``` |
[{"input": "7\natcoder\n4\nr a\nt e\nd v\na r\n", "output": "recover\n", "testtype": "stdin"}, {"input": "3\nabc\n4\na a\ns k\nn n\nz b\n", "output": "abc\n", "testtype": "stdin"}, {"input": "34\nsupercalifragilisticexpialidocious\n20\ng c\nl g\ng m\nc m\nr o\ns e\na a\no f\nf s\ne t\nt l\nd v\np k\nv h\nx i\nh n\nn j\ni r\ns i\nu a\n", "output": "laklimamriiamrmrllrmlrkramrjimrial\n", "testtype": "stdin"}] |
| doubao | ```python N = int(input()) S = input() Q = int(input()) for _ in range(Q): c, d = input().split() S = S.replace(c, d) print(S) ``` |
[{"input": "7\natcoder\n4\nr a\nt e\nd v\na r\n", "output": "recover\n", "testtype": "stdin"}, {"input": "3\nabc\n4\na a\ns k\nn n\nz b\n", "output": "abc\n", "testtype": "stdin"}, {"input": "34\nsupercalifragilisticexpialidocious\n20\ng c\nl g\ng m\nc m\nr o\ns e\na a\no f\nf s\ne t\nt l\nd v\np k\nv h\nx i\nh n\nn j\ni r\ns i\nu a\n", "output": "laklimamriiamrmrllrmlrkramrjimrial\n", "testtype": "stdin"}] |
| gpto1 | ```python # YOUR CODE HERE import sys import threading def main(): import sys import bisect sys.setrecursionlimit(1 << 25) input = sys.stdin.readline N = int(sys.stdin.readline()) S = sys.stdin.readline().strip() Q = int(sys.stdin.readline()) operations = [] for _ in range(Q): c_i, d_i = sys.stdin.readline().strip().split() operations.append((c_i, d_i)) mapping = {chr(ord('a') + i): chr(ord('a') + i) for i in range(26)} for c_i, d_i in reversed(operations): mapping[c_i] = mapping[d_i] result = ''.join(mapping[c] for c in S) print(result) threading.Thread(target=main).start() ``` |
[{"input": "7\natcoder\n4\nr a\nt e\nd v\na r\n", "output": "recover\n", "testtype": "stdin"}, {"input": "3\nabc\n4\na a\ns k\nn n\nz b\n", "output": "abc\n", "testtype": "stdin"}, {"input": "34\nsupercalifragilisticexpialidocious\n20\ng c\nl g\ng m\nc m\nr o\ns e\na a\no f\nf s\ne t\nt l\nd v\np k\nv h\nx i\nh n\nn j\ni r\ns i\nu a\n", "output": "laklimamriiamrmrllrmlrkramrjimrial\n", "testtype": "stdin"}] |
| kimi | ```python # YOUR CODE HERE n = int(input()) s = list(input()) q = int(input()) d = {} for _ in range(q): (c, d_) = input().split() if c in d: d[c] = d_ if d[c] != c else d_ else: d[c] = d_ for i in range(n): if s[i] in d: s[i] = d[s[i]] print(''.join(s)) ``` |
[{"input": "7\natcoder\n4\nr a\nt e\nd v\na r\n", "output": "recover\n", "testtype": "stdin"}, {"input": "3\nabc\n4\na a\ns k\nn n\nz b\n", "output": "abc\n", "testtype": "stdin"}, {"input": "34\nsupercalifragilisticexpialidocious\n20\ng c\nl g\ng m\nc m\nr o\ns e\na a\no f\nf s\ne t\nt l\nd v\np k\nv h\nx i\nh n\nn j\ni r\ns i\nu a\n", "output": "laklimamriiamrmrllrmlrkramrjimrial\n", "testtype": "stdin"}] |
| minimax | ```python # YOUR CODE HERE from collections import defaultdict # Read the inputs N = int(input()) S = input() Q = int(input()) operations = defaultdict(str) # Process the operations for _ in range(Q): c_i, d_i = input().split() operations[c_i] = d_i # Apply the operations to the string S for c_i, d_i in operations.items(): S = S.replace(c_i, d_i) # Print the final string S print(S) ``` |
[{"input": "7\natcoder\n4\nr a\nt e\nd v\na r\n", "output": "recover\n", "testtype": "stdin"}, {"input": "3\nabc\n4\na a\ns k\nn n\nz b\n", "output": "abc\n", "testtype": "stdin"}, {"input": "34\nsupercalifragilisticexpialidocious\n20\ng c\nl g\ng m\nc m\nr o\ns e\na a\no f\nf s\ne t\nt l\nd v\np k\nv h\nx i\nh n\nn j\ni r\ns i\nu a\n", "output": "laklimamriiamrmrllrmlrkramrjimrial\n", "testtype": "stdin"}] |
| wenxinyiyan | ```python # Read the input values N = int(input()) S = input() Q = int(input()) # Perform the operations for _ in range(Q): c_i, d_i = input().split() S = S.replace(c_i, d_i) # Print the final string print(S) ``` |
[{"input": "7\natcoder\n4\nr a\nt e\nd v\na r\n", "output": "recover\n", "testtype": "stdin"}, {"input": "3\nabc\n4\na a\ns k\nn n\nz b\n", "output": "abc\n", "testtype": "stdin"}, {"input": "34\nsupercalifragilisticexpialidocious\n20\ng c\nl g\ng m\nc m\nr o\ns e\na a\no f\nf s\ne t\nt l\nd v\np k\nv h\nx i\nh n\nn j\ni r\ns i\nu a\n", "output": "laklimamriiamrmrllrmlrkramrjimrial\n", "testtype": "stdin"}] |
| zhipu | ```python def main(): import sys input = sys.stdin.read data = input().split() n = int(data[0]) s = list(data[1]) q = int(data[2]) operations = data[3:] # Create a dictionary to map characters to their final replacements char_map = {} for i in range(q): c_i = operations[2 * i] d_i = operations[2 * i + 1] # If c_i is already mapped, update the mapping to the new character d_i if c_i in char_map: # If d_i is also mapped, we need to map c_i to the final character of d_i if d_i in char_map: char_map[c_i] = char_map[d_i] else: char_map[c_i] = d_i else: char_map[c_i] = d_i # Apply the final mappings to the string s for i in range(n): if s[i] in char_map: s[i] = char_map[s[i]] # Join the list into a string and print the result print(''.join(s)) if __name__ == "__main__": main() ``` |
[{"input": "7\natcoder\n4\nr a\nt e\nd v\na r\n", "output": "recover\n", "testtype": "stdin"}, {"input": "3\nabc\n4\na a\ns k\nn n\nz b\n", "output": "abc\n", "testtype": "stdin"}, {"input": "34\nsupercalifragilisticexpialidocious\n20\ng c\nl g\ng m\nc m\nr o\ns e\na a\no f\nf s\ne t\nt l\nd v\np k\nv h\nx i\nh n\nn j\ni r\ns i\nu a\n", "output": "laklimamriiamrmrllrmlrkramrjimrial\n", "testtype": "stdin"}] |
| deepseek-v3 | ```python # YOUR CODE HERE def main(): import sys input = sys.stdin.read data = input().split() N = int(data[0]) S = data[1] Q = int(data[2]) # Initialize a mapping from each character to itself mapping = {chr(ord('a') + i): chr(ord('a') + i) for i in range(26)} # Process each operation index = 3 for _ in range(Q): c = data[index] d = data[index + 1] index += 2 # Update the mapping: for all characters that map to c, map them to d for key in mapping: if mapping[key] == c: mapping[key] = d # Apply the final mapping to the string S result = [] for char in S: result.append(mapping[char]) print(''.join(result)) if __name__ == "__main__": main() ``` |
[{"input": "7\natcoder\n4\nr a\nt e\nd v\na r\n", "output": "recover\n", "testtype": "stdin"}, {"input": "3\nabc\n4\na a\ns k\nn n\nz b\n", "output": "abc\n", "testtype": "stdin"}, {"input": "34\nsupercalifragilisticexpialidocious\n20\ng c\nl g\ng m\nc m\nr o\ns e\na a\no f\nf s\ne t\nt l\nd v\np k\nv h\nx i\nh n\nn j\ni r\ns i\nu a\n", "output": "laklimamriiamrmrllrmlrkramrjimrial\n", "testtype": "stdin"}] |