2754: el psy congroo
题目描述
凶真被分配了一项任务,得到整数 1 到 n 所有数字的不重复的排列,即 n 的全排列。
这项任务实在太简单了,凶真不想去做,毕竟电话微波炉(暂定)的研究尚未完成,于是他把这个任务交给了你。
输入
一个整数 n。
1≤n≤9
输出
由数字 1∼n 组成的所有不重复的数字排列,每行一个序列。数字之间由空格分开。注意按照字典序输出。
样例输入
3
样例输出
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
好多种方式都能实现全排列,这里介绍一个全排列函数next_permutation();
#include<bits/stdc++.h>
using namespace std;
int arr[9] = {1,2,3,4,5,6,7,8,9};
int main(){
int n;
cin >> n;
do{
for(int i = 0; i < n; i++){
printf("%d ",arr[i]);
}
printf("\n");
}while(next_permutation(arr, arr+n));
}
2749: 小Z想上王者
题目描述
小S是一位自走棋的爱好者,他喜欢当第一的快感,但他是室友小Z更喜欢稳定拿最低分。已知一场游戏第一名、第二名……第八名分别加40 30 20 10 -10 -20 -30 -40分,现在给出小Z的近n场的游戏,你能计算出他现在的段位吗?
注意,小Z的初始段位分数为0,小Z的分数不可能低于0
Fe:[0,100)
Cu:[100,200)
Ag:[200,300)
Au:[300,400)
Pt:[400,正无穷)
输入
第一行给出n,代表小Z进行了n场游戏。
第二行给出一行字符串包含(1~8)代表小Z这n场的游戏名次。
1<=n<=1000
输出
仅一行,代表小Z现在的段位。
样例输入
5 11558
样例输出
Fe
被坑了(不好好读题的下场),得分不可能变成负,最低是0。
#include<bits/stdc++.h>
using namespace std;
int main(){
int arr[9] = {0,40,30,20,10,-10,-20,-30,-40};
int n;
string str;
cin >> n;
int ans = 0;
cin >> str;
for(int i = 0; i < str.length(); i++){
ans = ans + arr[str[i]-'0'];
if(ans < 0){
ans = 0;
}
}
if(ans >= 0 && ans < 100){
cout <<"Fe";
}else if(ans < 200){
cout <<"Cu";
}else if(ans < 300){
cout << "Ag";
}else if(ans < 400){
cout << "Au";
}else{
cout << "Pt";
}
}