ltx_zero

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

PAT B1006

没有难度,单独样例不需要EOF检测

#include<stdio.h>
#include<string.h>
int main()
{
    int num;
    int bai;
    int shi;
    int yi;
    scanf("%d",&num);
    bai=num/100;
    shi=num%100/10;
    yi=num%10;
    while(bai>0)
    {
        bai--;
        printf("B");
    }
    while(shi>0)
    {
        shi--;
        printf("S");
    }
    for(int i=1;i<=yi;i++)
        printf("%d",i);
    return 0;
}
View Code

 PAT B1021

没有难度

#include<stdio.h>
#include<string.h>
int main()
{
    char n[1005];
    int a[10];
    scanf("%s",n);
    memset(a,0,sizeof(a));
    int len=strlen(n);
    for(int i=0;i<len;i++)
        a[n[i]-'0']++;
    for(int i=0;i<=9;i++)
    {
        if(a[i]!=0)
            printf("%d:%d\n",i,a[i]);
    }
    return 0;
}
View Code

 PAT B1031

没啥难度,注意一下,几天不做题,刚开始总忘了写读取数据的部分

还有就是,如果是一个char数组,里面的1234 要 char str[]={'1','2','3','4'}

这道题如果没有那个X赋值就是错的了的而且自己没发现,一定要注意!

#include<stdio.h>
#include<string.h>
int quan[17]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
char yz[11]={'1','0','X','9','8','7','6','5','4','3','2'};
bool isnumstring(char str[])
{
    int len=strlen(str);
    for(int i=0;i<len;i++)
        if(str[i]==false)
        return false;
    return true;
}
int main()
{
    int n;
    bool pd=true;
    char str[1000];
    scanf("%d",&n);
    while(n--)
    {
        getchar();
        scanf("%s",str);
        if(!isnumstring(str))
        {
            printf("%s\n",str);
            pd=false;
            continue;
        }
        int sumnum=0;
        for(int i=0;i<=16;i++)
        {
            sumnum+=quan[i]*(str[i]-'0');
        }
        if(yz[sumnum%11]==str[17])
            continue;
        printf("%s\n",str);
        pd=false;
    }
    if(pd==true) printf("All passed\n");
    return 0;
}
View Code

 

posted on 2019-09-01 20:09  ltx_zero  阅读(149)  评论(0编辑  收藏  举报