天天看點

1081 檢查密碼(C語言)

設計思路:
  • 又是一道如何正确處理輸入的題目
編譯器:C (gcc)
#include <stdio.h>

int main()
{
        char c;
        int n, count, digit, alpha, notdot;

        scanf("%d", &n);
        while (getchar() != '\n')
                continue;

        while (n--) {
                count = 0; alpha = 0;
                digit = 0; notdot = 0;
                while ((c = getchar()) != '\n') {
                        count++;
                        if (isdigit(c))
                                digit++;
                        else if (isalpha(c))
                                alpha++;
                        else if (c != '.')
                                notdot++;
                }
                if (count < 6)
                        puts("Your password is tai duan le.");
                else if (notdot)
                        puts("Your password is tai luan le.");
                else if (alpha && !digit)
                        puts("Your password needs shu zi.");
                else if (digit && !alpha)
                        puts("Your password needs zi mu.");
                else
                        puts("Your password is wan mei.");
        }

        return 0;
}