A. My First Sorting Problem
You are given two integers x and y. Output two integers: the minimum of x and y, followed by the maximum of x and y.
题意:
给你两个整数求出最小值和最大值
Code:
#include<bits/stdc++.h> using namespace std; #define debug(x) cerr << #x << ": " << x << '\n'; void solve() { int x, y; cin >> x >> y; cout << min(x, y) << ' ' << max(x, y) << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int _ = 1; cin >> _; while(_--) solve(); return 0; }
B. Different String
You are given a string s consisting of lowercase English letters. Rearrange the characters of s to form a new string r that is not equal to s, or report that it's impossible. 给你一个字符串包含小写字母 改变s的位置使得r != s 是否存在 否则不可能
思路:
不难发现 只要字符串不是相同的字母 那么就可以改变它的位置
Code:
#include<bits/stdc++.h> using namespace std; #define debug(x) cerr << #x << ": " << x << '\n'; void solve() { string s; cin >> s; int len = s.size(); bool ok = false; for (int i = 1; i < len; i++) { if (s[i] != s[i - 1]) { swap(s[i], s[i - 1]); ok = true; } } if (ok) cout << "YES\n" << s << '\n'; else cout << "NO\n"; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int _ = 1; cin >> _; while(_--) solve(); return 0; }
标签:ok,cout,int,944,Codeforces,补题,using,Div From: https://www.cnblogs.com/youhualiuh/p/18187051