在线编译器 C

#include <stdio.h> int main() { int n, digit = 0; scanf("%d", &n); if (n < 0) { n = -n; } int save = n; while (digit <= 9) { int cnt = 0; n = save; while (n > 0) { if (n % 10 == digit) { cnt++; } n = 9; } if (cnt >= 2) { printf("NO\n"); return 0; } digit++; } printf("YES\n"); return 0; }
This program attempts to check if a number has any digit that appears more than once. It loops through digits 0 to 9, counts occurrences of each digit in the number, and prints "NO" if any digit appears at least twice, otherwise "YES". However, the logic inside the inner while loop is incorrect.

- Inside the inner while loop, you set `n = 9;` after checking one digit. This breaks the loop immediately and prevents counting the remaining digits of the original number. Think about what value `n` should be updated to in order to continue removing digits one by one.
- The variable `save` is used to restore `n` for each digit, but the inner loop modifies `n` incorrectly. Consider how to correctly extract each digit from the saved number without destroying it for the next digit check.