7-5 环形解密(简)
这个题直接就是取模向前移动和向后移动
#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;
struct data {
string id;
int x;
int y;
};
struct data a[1004];
signed main () {
ios::sync_with_stdio(false);
char x;
int step;
cin >> x >> step;
if (step < 0) { //小于0向前移动
step = -step; //将step变成正的
cout << (char)(((x - 'a') + step) % 26 + 'a'); //先前循环移动就可以了
} else {
step = 2600000000 - step; //向后移动,比如向后移动3个就相当于向前移动26-3个位置
//让很大的一个26的倍数减去step,然后就相当于将这个向后移动改成向前移动了,26的`倍数要足够大
cout << (char)(((x - 'a') + step) % 26 + 'a'); //打印结果
}
return 0;
}
7-8 考试座位号
这个题直接用结构体储存然后,进行m次查询就可以
#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;
struct data {
string id;//编号
int x;//试机座位号
int y;//考试座位号
};
struct data a[1004];
signed main () {
ios::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i].id >> a[i].x >> a[i].y; //读入数据
}
int m;
cin >> m;
while (m--) {
int b;
cin >> b;
for (int i = 0; i < n; i++) {
if (b == a[i].x) { //当找到试机座位号
cout << a[i].id << ' ' << a[i].y; //打印编号和考试座位号
cout << '\n';
break;
}
}
}
return 0;
}
7-2 排队候饭
这个题直接用贪心来做,先用sort排序然后从最小的开始检查当发现但当前的不能让其高兴的时候直接假想让他排到最后
#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;
int a[100005];
signed main () {
ios::sync_with_stdio(false);
string s;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n); //排序
int cnt = 0;
int res = 0;
for (int i = 0; i < n; i++) {
if (cnt <= a[i]) { //当cnt小于等于a[i]的时候
res++;//让结果加1
cnt = cnt + a[i]; //让cnt加上当前的值
}
}
cout << res; //打印
return 0;
}
未完待续
标签:练习题,cout,int,long,ICPC,step,2022,include,define From: https://www.cnblogs.com/harper886/p/17149745.html