atcoder集

youhualiuh / 2024-04-28 / 原文

AtCoder Beginner Contest 351

A - The bottom of the ninth(签到题)

 

Code:

#include<bits/stdc++.h>
    
using namespace std;
#define debug(x) cerr << #x << ": " << x << '\n';
    
int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int ans = 0;
    for (int i = 1; i <= 9; i++) {
        int x; cin >> x;
        ans += x;
    }
    for (int i = 1; i <= 8; i++) {
        int x; cin >> x;
        ans -= x;
    }
    cout << ans + 1 << '\n';
    return 0;
}

B - Spot the Difference

思路:

给你两个网格进行比较 只有一个字符不一样输出这个索引的位置 索引从1开始

Code:

#include<bits/stdc++.h>
	
using namespace std;
#define debug(x) cerr << #x << ": " << x << '\n';
	
int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n; cin >> n;
	vector <string> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) {
		string b; cin >> b;
		for (int j = 0; j < n; j++) {
			if (a[i][j] != b[j]) {
				cout << i + 1 << ' ' << j + 1 << '\n';
			}
		}
	}
	return 0;
} 

  

C - Merge the balls 

Code:

#include<bits/stdc++.h>
	
using namespace std;
#define debug(x) cerr << #x << ": " << x << '\n';
	
int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n; cin >> n;
	vector <int> ver;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		ver.push_back(x);
		while (ver.size() >= 2 && ver.back() == ver[ver.size() - 2]) {
			ver.pop_back();
			ver.back() ++;
		}
	}
	cout << ver.size() << '\n';
	return 0;
}