菜鸡的代码大佬勿喷

注:不一定是最优解嗷,懒得改了/捂脸

A. 身份证号码最后一位

运行时间限制: 1000运行内存限制: 65536
作者: bupt_admin是否specialjudge: False

题目描述

输入样例

2
34052419800101001X
310105199412049278

输出样例

right
wrong

示例代码

#include<stdio.h>

const int xishu[17] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
const char duiying[11] = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};

int main()
{
    int T;
    scanf("%d", &T);
    char a[19];
    while (T--)
    {
        scanf("%s", a);
        int sum = 0;
        int i = 0;
        for (i = 0; i < 17; i++)
        {
            sum += (a[i] - '0') * xishu[i];
        }
        if (duiying[sum % 11] == a[17])
        {
            printf("right\n");
        }
        else
        {
            printf("wrong\n");
        }
    }
    return 0;
}

B. 实验9_1_括号匹配

运行时间限制: 1000运行内存限制: 65536
作者: scshuanghai是否specialjudge: False

题目描述

问题描述:
任意给定一个字符串,字符串中包含除了空格、换行符之外的任意字符。你的任务是检测字符串中的小括号是否配对,即“(”与“)”是否配对。如字符串“((a+b)(c+d))”中小括号是配对的,而“((a+b))c+d))”则不配对。

输入与输出要求:
输入一个长度不超过100的非空字符串,该字符串中不会出现空格、换行符。输出检测结果。

输入样例

((a+b)*(c+d))
((a+b)*)c+d))

输出样例

parentheses match!
parentheses do not match!

示例代码

#include<stdio.h>

int main()
{
    int s[101] = {0};
    int you = 0;
    char a[101];
    int flag = 1;
    scanf("%s", a);
    int i, j;
    for (i = 0; a[i] != '\0'; i++)
    {
        if (a[i] == '(')
        {
            int tmpflag = 1;
            for (j = i; a[j] != '\0'; j++)
            {
                if (a[j] == ')' && s[j] == 0)
                {
                    s[j] = 1;
                    tmpflag = 0;
                    you = j;
                    break;
                }
            }
            if (tmpflag)
            {
                flag = 0;
            }
        }
    }
    for (i = you + 1; a[i] != '\0'; i++)
    {
        if (a[i] == ')')
        {
            flag = 0;
        }
    }
    if (flag)
    {
        printf("parentheses match!");
    }
    else
    {
        printf("parentheses do not match!");
    }
    return 0;
}

C. 实验9_3_字母统计

运行时间限制: 1000运行内存限制: 65536
作者: scshuanghai是否specialjudge: False

题目描述

问题描述:
任意给定一个字符串,字符串中包含除了空格、换行符之外的的任意字符。你的任务是统计出现在该字符串中的各字母(即“A—Z”,“a—z”)的个数(区分大小写)。

输入与输出要求:
输入一个长度不超过100的非空字符串。字符串中不会出现空格、换行符。输出字符串中出现的字母的统计信息,每个字母的统计信息占一行,按照字母的ASCII码的顺序输出。

注意单词“time”不论单复数,一律输出复数形式“times”。

输入样例

AAAsdf&^%DF879as

输出样例

The character A has presented 3 times.
The character D has presented 1 times.
The character F has presented 1 times.
The character a has presented 1 times.
The character d has presented 1 times.
The character f has presented 1 times.
The character s has presented 2 times.

示例代码

#include<stdio.h>

int main()
{
    int count[200] = {0};
    char a[101];
    scanf("%s", a);
    int i = 0;
    for (i = 0; a[i] != '\0'; i++)
    {
        if ((a[i] >= 'A' && a[i] <= 'Z') || (a[i] >= 'a' && a[i] <= 'z'))
        {
            count[a[i]]++;
        } 
    }
    for (i = 0; i < 200; i++)
    {
        if (count[i])
        {
            printf("The character %c has presented %d times.\n", i, count[i]);
        }
    }
    return 0;
}

D. 实验9_9_字符串加密

运行时间限制: 1000运行内存限制: 65536
作者: scshuanghai是否specialjudge: False

题目描述

问题描述:
任意给定一个字符串,与两个编码表,要求对该字符串进行加密。字符串中只包含大写字母与小写字母。编码表是字母表的一个重新排列,第一个编码表为大写字母编码表,第二个编码表为小写字母编码表。
例如:
字母表为:
(大写字母表:ABCDEFGHIJKLMNOPQRSTUVWXYZ)
(小写字母表:abcdefghijklmnopqrstuvwxyz)
编码表为:
(大写字母编码表: JKLMQRYZABCISTNOPDGHXEFUVW)
(小写字母编码表: bcljakfxpdqweozrsthiymnguv)
编码表的功能是根据字母在字母表中的序号,把该字母替换成编码表中相应序号上的字母。
例如,字母‘A’在字母表中序号为1,而大写字母编码表中序号为1的是字母‘J’,因此‘A’被编码为‘J’,而字符串“ACDza”将编码为“JLMvb”。
字符串加密过程:
首先把待加密字符串中所有的字母改写成该字母的下一个字母,字母如果为‘Z’或‘z’则分别改写成字母‘A’或‘a’。然后将新得到的字符串根据两个编码表进行编码。编码后的字符串即为结果字符串。

输入与输出要求:
输入三个字符串,第一个字符串为非空的待加密的字符串,长度不大于100,该字符串中只可能出现大写字母与小写字母。第二个字符串为大写字母编码表,即26个大写字母,每个大写字母只能出现一次。第三个字符串为小写字母编码表,即26个小写字母,每个小写字母只能出现一次。输出结果字符串,占一行。

输入样例

IlovelanguageC
OPDGHSTABNRYZCQJKLMIXEFUVW
hpzaeongxrbcljwtskfymdqiuv

输出样例

NltqolpwgdpgoG

示例代码

#include<stdio.h>

int main()
{
    char x[101];
    char A[28];
    char a[28];
    scanf("%s", x);
    scanf("%s", A);
    scanf("%s", a);
    int i;
    for (i = 0; x[i] != '\0'; i++)
    {
        x[i]++;
        if (x[i] == 'Z' + 1 || x[i] == 'z' + 1)
        {
            x[i] -= 26;
        }
    }
    for (i = 0; x[i] != '\0'; i++)
    {
        if (x[i] >= 'A' && x[i] <= 'Z')
        {
            printf("%c", A[x[i] - 'A']);
        }
        else
        {
            printf("%c", a[x[i] - 'a']);
        }
    }
    return 0;
}
分类: OJ代码