Online Compiler Nasm

extern scanf, printf, strcmp, strcpy section .data fmt_n db "%u", 0 fmt_s db "%10s", 0 fmt_out db "%u", 10, 0 section .bss n resd 1 i resd 1 j resd 1 unique_cnt resd 1 temp resb 11 strings resb 500 * 11 section .text global main main: push ebp mov ebp, esp push n push fmt_n call scanf add esp, 8 mov dword [unique_cnt], 0 mov dword [i], 0 read_loop: mov eax, [i] cmp eax, [n] jge finish push temp push fmt_s call scanf add esp, 8 mov dword [j], 0 check_loop: mov eax, [j] cmp eax, [unique_cnt] jge add_string imul eax, 11 lea ebx, [strings + eax] push temp push ebx call strcmp add esp, 8 test eax, eax jz already_exists inc dword [j] jmp check_loop add_string: mov eax, [unique_cnt] imul eax, 11 lea ebx, [strings + eax] push temp push ebx call strcpy add esp, 8 inc dword [unique_cnt] already_exists: inc dword [i] jmp read_loop finish: push dword [unique_cnt] push fmt_out call printf add esp, 8 xor eax, eax mov esp, ebp pop ebp ret
Вот разбор кода:

1) **Что делает код:**  
Программа считывает `n` строк (до 10 символов каждая), сохраняет только уникальные строки в массив `strings` и выводит количество уникальных строк. Для проверки уникальности используется `strcmp`, для копирования — `strcpy`.

2) **Подсказки:**  
- Проверьте, что буфер `temp` (11 байт) достаточен для строки с учётом нуль-терминатора. Если ввод содержит ровно 10 символов, `scanf` с форматом `%10s` запишет 11 байт (10 символов + `\0`), что помещается в `temp`.  
- В цикле `check_loop` сравнение `j` с `unique_cnt` перед вызовом `strcmp` корректно, но обратите внимание: после `strcmp` результат проверяется на ноль — если строки равны, происходит переход на `already_exists`, иначе цикл продолжается. Убедитесь, что `j` увеличивается только при несовпадении.