cf(div3)a,b题

A - Compare T-Shirt Sizes
Two T-shirt sizes are given: aa and bb. The T-shirt size is either a string M or a string consisting of several (possibly zero) characters X and one of the characters S or L.

For example, strings M, XXL, S, XXXXXXXS could be the size of some T-shirts. And the strings XM, LL, SX are not sizes.

The letter M stands for medium, S for small, L for large. The letter X refers to the degree of size (from eXtra). For example, XXL is extra-extra-large (bigger than XL, and smaller than XXXL).

You need to compare two given sizes of T-shirts aa and bb.

The T-shirts are compared as follows:

any small size (no matter how many letters X) is smaller than the medium size and any large size;
any large size (regardless of the number of letters X) is larger than the medium size and any small size;
the more letters X before S, the smaller the size;
the more letters X in front of L, the larger the size.
For example:

XXXS < XS
XXXL > XL
XL > M
XXL = XXL
XXXXXS < M
XL > XXXS

Input

The first line of the input contains a single integer tt (1≤t≤10^4 ) — the number of test cases.
Each test case consists of one line, in which aa and bb T-shirt sizes are written.
The lengths of the strings corresponding to the T-shirt sizes do not exceed 
5050. It is guaranteed that all sizes are correct.
Output

For each test case, print on a separate line the result of comparing 
a and b T-shirt sizes (lines "<", ">" or "=" without quotes).

Sample 1
Inputcopy    
6
XXXS   XS
XXXL   XL
XL     M
XXL   XXL
XXXXXS M
L      M
Outputcopy
<
>
>
=
<
>
题解:S是最小尺码,M是中等尺码,L是最大尺码。
满足要求:
(1)S (2)S特殊考虑,当在S中X越多S越小
(3)当不是S时,相同尺码时考虑X的个数,X越多尺码越大

小菜鸡的代码(QAQ)

#include
#include
#include
#include
using namespace std;
const int N=110000;
string a,b;
int main(){
	int n;
	cin>>n;
	while(n--){
		cin>>a;
		cin>>b;
		if(a[a.size()-1]=='S'&&b[b.size()-1]=='M'||a[a.size()-1]=='S'&&b[b.size()-1]=='L'||a[a.size()-1]=='M'&&b[b.size()-1]=='L'){
			cout<<"<"<"<"<b.size())cout<<">"<

B - Funny Permutation

A sequence of nn numbers is called permutation if
it contains all numbers from 11 to nn exactly once. 
For example, the sequences [3, 1, 4, 2][3,1,4,2], [11] 
and [2,1][2,1] are permutations, but [1,2,1][1,2,1], [0,1][0,1]
and [1,3,4][1,3,4] are not.For a given number nn you need 
to make a permutation pp such that two requirements are
satisfied at the same time:For each element pi, at least one 
of its neighbors has a value that differs from the value of pi
by one. That is, for each element pi(1≤i≤n), at least one of 
its neighboring elements (standing to the left or right of pi
must be pi + 1, or pi - 1the permutation must have no fixed
points. That is, for every i (1≤i≤n), pi=i must be satisfied.
Let's call the permutation that satisfies these requirements 
funny.For example, let n=4. Then [4, 3, 1, 24,3,1,2] is a funny
permutation, since:
to the right ofp1=4 is p2=p1-1=4-1=3;
to the left of p2=3 is p1=p2+1=3+1=4;
to the right of p3=1 is p4=p3+1=1+1=2;
to the left of p4=2 is p3=p4-1=2-1=1.
for all i is pi/=i.
For a given positive integer nn, outputany funny permutation of
length nn, or output -1 iffunny permutation of length nn does not exist.

Input

The first line of input data contains a single integer t(1≤t≤10^4)
— the number of test cases.The description of the test cases follows.
Each test case consists of f single line containing one integer n
( 2≤n≤2⋅10^5 ).It is guaranteed that the sum of nn over all test
cases does not exceed2⋅10 ^5.

Output

For each test case, print on a separate line:
any funny permutation p of length n;
or the number -1 if the permutation you are looking for does not exist.

Sample 1
Inputcopy    
5
4
3
7
5
2

Outputcopy

3 4 2 1
-1
6 7 4 5 3 2 1
5 4 1 2 3
2 1
 
 题解:
 对于n是偶数的情况,我们直接构造出逆序即可。

对于奇数的情况,如果直接逆序的话(n + 1) / 2的位置会出现符合,我们需要和左边或者右边交换一下即可。

注意特盘1 3 5的情况。
 

#include
#include
#include
#include
using namespace std;
const int N=110000;
string a,b;
int n;
void solve() {
    cin >> n;
    if(n % 2 == 0) {
        for(int i = 1; i <= n ; i ++ ) 
            cout << n - i + 1 << " ";
        cout << endl;
    } else {
        if(n == 1 || n == 3) cout << -1 << endl;
        else if(n == 5) {
            cout << 5 << " " << 4 << " " << 1 << " " << 2 << " " << 3 << endl;
        }
        else {
            for(int i = 1; i <= n ; i ++ ) {
                if(i == n / 2) cout << n - i << " ";
                else if(i == n / 2 + 1) cout << n - i + 2 << " ";
                else cout << n - i + 1 << " ";
            }
            cout << endl;
        }
    }
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve();
	}
}
 

 (借鉴了我朋友只需要特判3 后面就先输出 n n-1 在依次输出1到n-2)

你可能感兴趣的:(c++)