1. 程式人生 > 其它 >CDUT_ITA 第二週 Level3

CDUT_ITA 第二週 Level3

出題人你能不能別出模擬了我都寫吐了

碼力題,真沒啥思維含量,

注意細節火速AK

啥 我為什麼沒火速AK 那當然是因為我菜啊

A

檢測一下每一條是否為一個顏色,每一列上下是否為一個顏色就好。

點選檢視程式碼
#include<bits/stdc++.h>
using namespace std;
int n, m, sum;
set<int>vis;
string a[105];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			if (vis.find(a[i][j]) != vis.end()) {
				sum++;
				vis.insert(a[i][j]);
			}
	if (sum > 10) {
		cout << "NO";
		return 0;
	}
	for(int i=1;i<n;i++)
		if (a[i][0] == a[i - 1][0]) {
			cout << "NO";
			return 0;
		}
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			if (a[i][0] != a[i][j]) {
				cout << "NO";
				return 0;
			}
	cout << "YES";
	return 0;
}

B

string經典好題
首先反轉字串使用reverse函式,從begin到end就可以了。
然後每次find一下a,如果找到a了再去find另一個b。
以及 find()中第二個引數為開始位置(預設0)

點選檢視程式碼
#include<bits/stdc++.h>
using namespace std;
string s, a, b;
int nowa = 998244353, nowb = -1;
int flag1, flag2;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> s >> a >> b;
	nowa = s.find(a);
	if (nowa != a.npos) {
		nowb = s.find(b, nowa + a.length());
	}
	else nowb = s.find(b);
	if (nowa != a.npos && nowb != b.npos) {
		flag1 = 1;
	}
	reverse(s.begin(), s.end());
	nowa = 998244353, nowb = -1;
	nowa = s.find(a);
	if (nowa != a.npos) {
		nowb = s.find(b, nowa + a.length());
	}
	else nowb = s.find(b);
	if (nowa != a.npos && nowb != b.npos) {
		flag2 = 1;
	}
	if (flag1 == 1 && flag2 == 1) {
		cout << "both";
	}
	if (flag1 == 1 && flag2 != 1) {
		cout << "forward";
	}
	if (flag1 != 1 && flag2 == 1) {
		cout << "backward";
	}
	if (flag1 != 1 && flag2 != 1) {
		cout << "fantasy";
	}
	return 0;
}

C

我們可以找到每一個@符號,然後往左右分別找一個字母。
只要可以放,就放。
就是這個可以放,需要注意的細節很多

點選檢視程式碼
#include<bits/stdc++.h>
using namespace std;
string a;
int cnt, now[205], vis[205], flag, ans[205];
int sum;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> a;
	if (a[0] == '@') {
		cout << "No solution";
		return 0;
	}
	for (int i = 0; i < a.length(); i++) {
		if (a[i] == '@') {
			now[++cnt] = i;
			if (a[i + 1] == a[i] || !a[i + 1]) {
				flag = 1;
			}
		}
	}
	if (cnt == 0 || flag == 1) {
		cout << "No solution";
		return 0;
	}
	for (int i = 1; i <= cnt; i++) {
		if (a[now[i] - 1] && a[now[i] + 1]) {
			if (!vis[now[i] - 1] && !vis[now[i] + 1]) {
				vis[now[i] - 1] = 1;
				vis[now[i] + 1] = 1;
				if (a[now[i] + 2]) {
					ans[++sum] = now[i] + 2;
				}
			}
			else {
				cout << "No solution";
				return 0;
			}
		}
	}
	int tmp = 1;
	for (int i = 0; i < a.length(); i++) {
		if (ans[tmp] == i && tmp < cnt) {
			cout << ",";
			tmp++;
		}
		cout << a[i];
	}
	return 0;
}

D

水題,直接找就行。

點選檢視程式碼
#include<bits/stdc++.h>
using namespace std;
int n, m;
int x = 0x7f, y = 0x7f;
int xx = -1, yy = -1;
string a[55];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i <= n; i++)
		for (int j = 0; j < m; j++) {
			if (a[i][j] == '*') {
				xx = max(i, xx);
				yy = max(j, yy);
				x = min(i, x);
				y = min(j, y);
			}
		}
	for (int i = x; i <= xx; i++) {
		for (int j = y; j <= yy; j++) {
			cout << a[i][j];
		}
		cout << endl;
	}
	return 0;
}