Codeforces Round 862 (Div. 2)
链接
A题
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no cout<<"NO"<<'\n'
using namespace std;
const int N = 1004;
void solve() {
int n;
scanf("%lld", &n);
int a[N];
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
}
//对a[1]到a[n]求出最后的异或值
int v = a[1];
for (int i = 2; i <= n; i++) {
v = a[i] ^ v;
}
if (v == 0) {//如果异或值为0的话,无论n是多少最后的异或值都为0
cout << 0 << '\n';
return;
}
if (n % 2 == 0) {//n为偶数相当于再对这个数异或偶数次最后肯定不为0
cout << -1 << '\n';
} else {
cout << v << '\n';//n为奇数相等于再对这个数异或奇数次最后为0
}
}
signed main () {
int t;
cin >> t;
while (t) {
solve();
t--;
}
return 0;
}
B题
将最后一个最小的字符串保存起来放到最前面就可以实现这个效果
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no cout<<"NO"<<'\n'
using namespace std;
const int N = 100008;
void solve() {
int n;
scanf("%lld", &n);
string s;
cin >> s;
int id = 0;
int mmin = 200;
for (int i = 0; i < (int)s.size(); i++) {
if (s[i] <= mmin) {
mmin = (int)s[i];
id = i;
}
}
//求存最小的字符和字符所在的位置id
cout << s[id];//打印这个字符
for (int i = 0; i < (int)s.size(); i++) {
if (i == id) {//打印的时候跳过这个字符
continue;
} else {
cout << s[i];//其他整除打印
}
}
cout << '\n';
}
signed main () {
int t;
cin >> t;
while (t) {
solve();
t--;
}
return 0;
}
标签:int,862,Codeforces,long,Div,include,define
From: https://www.cnblogs.com/harper886/p/17290908.html