B

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
char s[10005];
 
int main()
{
    int t;
    int len ,k;
    int i, j;
    int cnt;
 
    scanf("%d%*c", &t);
    while(t--)
    {
        memset(s, '\0', sizeof(s));
        scanf("%s", s);
        //puts(s);
        scanf("%d", &k);
        len = strlen(s);
 
        cnt=0;
        if(k*2 <= len)
        {
            i=0;
            j=len-k;
            while(i<k)
            {
                if(s[i]!=s[j] )
                {
                    cnt++;
                }
                i++;
                j++;
            }
            printf("%d\n", cnt ) ;
            continue;
        }
        else
        {
            i = 0;
            j = len-k;
            while(i<k)
            {
                if( s[i]==s[j] )
                {
                    i++;
                    j++;
                }
                else
                {
                    if( s[j]==s[j+j-i] )
                    {
                        s[i] = s[j];
                        cnt++;
                        i++;
                        j++;
                    }
                    else
                    {
                        s[j]=s[i];
                        i++;
                        j++;
                        cnt++;
                    }
                }
            }
            printf("%d\n", cnt );
            continue;
        }
    }
    return 0;
}

 

posted @   我喜欢旅行  阅读(153)  评论(0编辑  收藏  举报
编辑推荐:
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 现代计算机视觉入门之:什么是图片特征编码
· .NET 9 new features-C#13新的锁类型和语义
阅读排行:
· 手把手教你在本地部署DeepSeek R1,搭建web-ui ,建议收藏!
· Spring AI + Ollama 实现 deepseek-r1 的API服务和调用
· 《HelloGitHub》第 106 期
· 数据库服务器 SQL Server 版本升级公告
· C#/.NET/.NET Core技术前沿周刊 | 第 23 期(2025年1.20-1.26)
点击右上角即可分享
微信分享提示