QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#567320#9313. Make MaxXinkie_LWA 0ms1624kbC++141.1kb2024-09-16 11:06:032024-09-16 11:06:03

Judging History

你现在查看的是最新测评结果

  • [2024-09-18 15:56:24]
  • hack成功,自动添加数据
  • (/hack/836)
  • [2024-09-16 11:06:03]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:1624kb
  • [2024-09-16 11:06:03]
  • 提交

answer

#include <stdio.h>

int main() {
    int t;
    scanf("%d", &t); // 读取测试用例的数量
    while (t--) {
        int n;
        scanf("%d", &n); // 读取序列的长度
        int a[n];
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]); // 读取序列中的每个元素
        }

        int operations = 0;
        int i = 0;
        while (i < n) {
            // 找到连续相同元素的起始位置
            while (i + 1 < n && a[i] == a[i + 1]) {
                i++;
            }
            int start = i;
            // 找到连续相同元素的结束位置
            while (i + 1 < n && a[i] != a[i + 1]) {
                i++;
            }
            int end = i;
            // 如果end等于start,说明整个序列都是相同的元素,不能进行操作
            if (start != end) {
                operations++;
            }
            // 跳过已经处理的连续相同元素的段
            i++;
        }

        printf("%d\n", operations);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 1624kb

input:

4
2
1 2
2
2 2
7
1 1 1 2 2 2 2
3
1 2 3

output:

1
0
1
1

result:

wrong answer 3rd numbers differ - expected: '3', found: '1'