2010 div3

A

傻逼题目

#include <cmath> 
#include <iostream>

int a[110] = {0};
int x = 0;

int main()
{
    int t, n = 0;
    std::cin >> t;
    for(int i = 0; i < t; i++){
        int tmp = 0;
        std::cin >> n;
        for(int j = 0; j < n; j++){
            std::cin >> x;
            tmp += x * std::pow(-1, j);
        //  std::cout << tmp << std::endl;
        }
        std::cout << tmp << std::endl;
    }
    return 0;
}

B

#include <iostream>

int main(){
    int a, b = 0;
    std::cin >> a >> b;
    int arry[4] = {0};
    arry[a]++;
    arry[b]++;
    for(int i = 1; i <= 3; i++)
        if(arry[i] == 0)
            std::cout << i << std::endl;
    return 0;
}

C1

#include <bits/stdc++.h>
#include <string>

int main()
{
    std::string str;
    std::cin >> str;

    std::string s1 = str.substr(0, 2);
    int pos = str.find(s1, 2);

//  for(int i = pos + 2, j = 2; i < str.length(); i++, j++){
//      if(i == (str.length() - 1)){
//          std::cout << "YES" << std::endl << str.substr(pos);
//          break;
//      }else if(str[j] != str[i]){
//          std::cout << "NO" << std::endl;
//          break;
//      }
//  }

    while (pos != std::string::npos) {
        // 从 pos 开始进行比较
        bool match = true;
        for (int i = pos + 2, j = 2; i < str.length(); i++, j++) {
            if (j >= str.length() || i >= str.length() || str[j] != str[i]) {
                match = false;
                break;
            }
        }

        if (match) {
            std::cout << "YES" << std::endl << str.substr(pos) << std::endl;
            return 0; // 找到匹配后退出
        }

        // 如果没有匹配,继续寻找下一个位置
        pos = str.find(s1, pos + 1); // 从下一个位置继续查找
    }

    std::cout << "NO" << std::endl; // 如果没有找到任何匹配
    return 0;
}

C2

Hey!

If you have any non-algorithmic questions about the code, send me a message and I will be happy to help. I also hope to make more like-minded friends.