PTA12.09作业

PTA12.09作业_第1张图片

void delchar(char* str, char c)
{
    char* p = str;
int i = 0;
while (*p)
{
    if (*p != c)
    str[i++] = *p;
    p++;
}
str[i] = '\0';
}

PTA12.09作业_第2张图片

void f( char *p )
{
    int left = 0, i = 0;
    for(i = 0;;i++)
    {
        if(*(p+i)=='\0')
            break;
    }
    int right = i - 1;
    while(left

PTA12.09作业_第3张图片

int main()
{
    char str[30];
    gets(str);
    char* p = str;
    int i = 0;
    while (*p != '#')
    {
        if (*p >= 'A' && *p <= 'Z')
        {
            *p += 32;
            str[i++] = *p;
            p++;
        }
        else if (*p >= 'a' && *p <= 'z')
        {
            *p -= 32;
            str[i++] = *p;
            p++;
        }
        else
        {
            str[i++] = *p;
            p++;
        }
    }
    str[i] = '\0';
    printf("%s", str);
    return 0;
}

PTA12.09作业_第4张图片

int main()
{
    char str[80], c;
    gets(str);
    scanf("%c",&c);
    int count = 0;
    char* p=str;
    while(*p)
    {
        if(*p == c)
            count++;
        p++;
    }
    printf("%d",count);
}

PTA12.09作业_第5张图片

int is_shu(char* p)
{
    for (int i = 0; i < 17; i++)
    {
        if (*(p + i) <= '0' && *(p + i) >= '9')
        {
            return 0;
        }
    }
}
int Mod(char* p)
{
    int sum = 0;
    sum = ((*p)-'0') * 7 + (*(p + 1)-'0') * 9 + (*(p + 2)-'0') * 10 + (*(p + 3)-'0') * 5 + (*(p + 4)-'0') * 8 + (*(p + 5)-'0') * 4 + (*(p + 6)-'0') * 2 + (*(p + 7)-'0') * 1 + (*(p + 8)-'0') * 6 + (*(p + 9)-'0') * 3 + (*(p + 10)-'0') * 7 + (*(p + 11)-'0') * 9 + (*(p + 12)-'0') * 10 + (*(p + 13)-'0') * 5 + (*(p + 14)-'0') * 8 + (*(p + 15)-'0') * 4 + (*(p + 16)-'0') * 2;
    return sum % 11;
}
int True(char* p)
{
    if(is_shu(p))
        return 0;
    int ret = Mod(p);
    if (ret == 0)
    {
        if (*(p + 17) == '1')
            return 1;
        return 0;
    }
    if (ret == 1)
    {
        if (*(p + 17) == '0')
            return 1;
        return 0;
    }
    if (ret == 2)
    {
        if (*(p + 17) == 'X')
            return 1;
        return 0;
    }
    if (ret == 3)
    {
        if (*(p + 17) == '9')
            return 1;
        return 0;
    }
    if (ret == 4)
    {
        if (*(p + 17) == '8')
            return 1;
        return 0;
    }
    if (ret == 5)
    {
        if (*(p + 17) == '7')
            return 1;
        return 0;
    }
    if (ret == 6)
    {
        if (*(p + 17) == '6')
            return 1;
        return 0;
    }
    if (ret == 7)
    {
        if (*(p + 17) == '5')
            return 1;
        return 0;
    }
    if (ret == 8)
    {
        if (*(p + 17) == '4')
            return 1;
        return 0;
    }
    if (ret == 9)
    {
        if (*(p + 17) == '3')
            return 1;
        return 0;
    }
    if (ret == 10)
    {
        if (*(p + 17) == '2')
            return 1;
        return 0;
    }
}
int main()
{
    int n, a = 0, count = 0;
    char arr[20];
    scanf("%d", &n);
    getchar();
    a = n;
    while (n > 0)
    {
        gets(arr);
        if (True(arr))
            count++;
        else
        {
            printf("%s\n", arr);
        }
        n--;
    }
    if (count == a)
        printf("All passed");
}

你可能感兴趣的:(算法,数据结构)