
【CSP-J模拟赛十四】题解
T1
#include <bits/stdc++.h>
using namespace std;
#define int long long
int read() {
int s = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
s = s * 10 + c - '0';
c = getchar();
}
return s * f;
}
int n;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
n = read();
bool cond1 = (n % 2 == 0);
bool cond2 = (n > 4 && n <= 12);
cout << (cond1 && cond2 ? "1 " : "0 ");
cout << (cond1 || cond2 ? "1 " : "0 ");
cout << ((cond1 ^ cond2) ? "1 " : "0 ");
cout << (!cond1 && !cond2 ? "1" : "0");
return 0;
}
T2
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 105;
int m, a[N];
signed main() {
cin >> m;
int t = 0, lt = INT_MAX, cnt = 1;
for (int i = 1; i <= m; i++) {
cin >> t;
if (t != lt) {
if (cnt > 1)
cout << lt << " " << cnt << "\n";
lt = t;
cnt = 1;
} else
cnt++;
}
if (cnt > 1)
cout << lt << " " << cnt << "\n";
return 0;
}
T3
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
cout<<min(b,a-b);
return 0;
}
T4
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.size();
vector<int> cnt(26, 0);
vector<bool> inStack(26, false);
for (char c: s) {
cnt[c - 'a']++;
}
stack<char> st;
for (char c: s) {
cnt[c - 'a']--;
if (inStack[c - 'a']) continue;
while (!st.empty() && st.top() > c) {
if (cnt[st.top() - 'a'] == 0) {
break;
}
inStack[st.top() - 'a'] = false;
st.pop();
}
st.push(c);
inStack[c - 'a'] = true;
}
string result;
while (!st.empty()) {
result = st.top() + result;
st.pop();
}
cout << result << endl;
return 0;
}
T5
T6
- 感谢你赐予我前进的力量
赞赏者名单
因为你们的支持让我意识到写文章的价值🙏
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 Zyx-2012
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果