萌新打卡第。。。。天

只会模拟的,不会些进阶方法(DP+前缀和,BFS)还是不行的

1.万万没想到之聪明的编辑

我叫王大锤,是一家出版社的编辑。我负责校对投稿来的英文稿件,这份工作非常烦人,因为每天都要去修正无数的拼写错误。但是,优秀的人总能在平凡的工作中发现真理。我发现一个发现拼写错误的捷径:

1. 三个同样的字母连在一起,一定是拼写错误,去掉一个的就好啦:比如 helllo -> hello

2. 两对一样的字母(AABB型)连在一起,一定是拼写错误,去掉第二对的一个字母就好啦:比如 helloo -> hello

3. 上面的规则优先“从左到右”匹配,即如果是AABBCC,虽然AABB和BBCC都是错误拼写,应该优先考虑修复AABB,结果为AABCC

我特喵是个天才!我在蓝翔学过挖掘机和程序设计,按照这个原理写了一个自动校对器,工作效率从此起飞。用不了多久,我就会出任CEO,当上董事长,迎娶白富美,走上人生巅峰,想想都有点小激动呢!

……

万万没想到,我被开除了,临走时老板对我说: “做人做事要兢兢业业、勤勤恳恳、本本分分,人要是行,干一行行一行。一行行行行行;要是不行,干一行不行一行,一行不行行行不行。” 我现在整个人红红火火恍恍惚惚的……

请听题:请实现大锤的自动校对程序

#include <stdio.h>
#include <string.h>

int main() {
    int N;
    scanf("%d", &N);
    
    for(int i=0;i<N;i++){
        char s[1000];
        scanf("%s",s);
        int count=1;
        char temp=s[0];
        int temp_num=0;
        int n=strlen(s);
        char output[1000];
        int flag=1;
        for(int j=1;j<n;j++){
            if (s[j]==temp) {
                if(temp_num>=2){
                    if(count==1&&s[temp_num-1]==s[temp_num-2]&&s[temp_num-1]!='1'){
                        s[j]='1';
                        continue;
                    }
                    if(count==1&&flag==1){
                        s[j]='1';
                        continue;
                    }

                }
                if(count==2){
                    s[j]='1';
                }else{
                    count++;
                }
            }else{
                if(count==2){
                    flag=1;
                }else{
                    flag=0;
                }
                temp=s[j];
                temp_num=j;
                count=1;
            }
        }
        for(int q=0;q<n;q++){
            if(s[q]!='1')
                putchar(s[q]);
        }
        putchar('\n');
                   
    }
    

    return 0;
}

2、找零

Z国的货币系统包含面值1元、4元、16元、64元共计4种硬币,以及面值1024元的纸币。现在小Y使用1024元的纸币购买了一件价值为N(0<N≤1024)的商品,请问最少他会收到多少硬币?

这题靠土方法实现

#include <math.h>

#include <stdio.h>

int main() {

    int N;

    scanf("%d",&N);

    int a=1024-N;

    int output=0;

    int a1=a/64;

    int b1=a%64;

    int a2=b1/16;

    int b2=b1%16;

    int a3=b2/4;

    int b3=b2%4;

    int a4=b3/1;

    int b4=b3%1;

    printf("%d",a1+a2+a3+a4);

   

   

}

全部评论

相关推荐

点赞 1 评论
分享
牛客网
牛客企业服务