春节刷题day4:PAT
1031 查验身份证
1032 挖掘机技术哪家强
1033 旧键盘打字
1034 有理数四则运算
1035 插入与归并
1036 跟奥巴马一起编程
1037 在霍格沃茨找零钱
1038 统计同成绩学生
1039 到底买不买
1040 有几个PAT
1、1031 查验身份证
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<bitset>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<algorithm>
#include<vector>
#define ll long long
#define PI acos(-1.0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define esp 1e-5
#define lowbit(x) x & (-x)
using namespace std;
const int maxx = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll mod = 998244353;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int n, m, T;
int l, r, cnt, tot;
map<int, char> p;
string s, ans[maxx + 5];
int a[17] = {
7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
void init(){
p[0] = '1'; p[1] = '0'; p[2] = 'X'; p[3] = '9'; p[4] = '8';
p[5] = '7'; p[6] = '6'; p[7] = '5'; p[8] = '4'; p[9] = '3';
p[10] = '2';
}
int main(){
int i, j, k;
init();
while(cin >> n){
for(i = 0; i < n; i++){
cin >> s; int len = s.size();
bool ok = true;
for(j = 0, m = 0; j < 17; j++){
m += a[j] * (s[j] - '0');
if(s[j] > '9' || s[j] < '0'){
ans[tot++] = s; ok = false;
}
}
if(ok){
if(p[m % 11] != s[17]) ans[tot++] = s;
}
}
if(tot == 0) puts("All passed");
else{
for(i = 0; i < tot; i++) cout << ans[i] << endl;
}
}
return 0;
}
2、1032 挖掘机技术哪家强
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<bitset>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<algorithm>
#include<vector>
#define ll long long
#define PI acos(-1.0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define esp 1e-5
#define lowbit(x) x & (-x)
using namespace std;
const int maxx = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll mod = 998244353;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int n, m, T;
int l, r, cnt, tot;
int a[maxx + 5];
int main(){
int i, j, k;
while(cin >> n){
for(i = 0; i < n; i++){
cin >> l >> r;
a[l] += r; m = max(m, l);
}
int idx = 1, Max = a[1];
for(i = 2; i <= m; i++){
if(a[i] > Max){
Max = a[i]; idx = i;
}
}
cout << idx << " " << Max << endl;
}
return 0;
}
3、1033 旧键盘打字
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<bitset>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<algorithm>
#include<vector>
#define ll long long
#define PI acos(-1.0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define esp 1e-5
#define lowbit(x) x & (-x)
using namespace std;
const int maxx = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll mod = 998244353;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int n, m, T;
int l, r, cnt, tot;
map<char, bool> p;
string s, t;
int main(){
int i, j, k;
getline(cin, s);
bool f = false; int len = s.size();
for(i = 0; i < len; i++){
if(s[i] == '+') f = true;
if(s[i] >= 'A' && s[i] <= 'Z') p['a' + (s[i] - 'A')] = true;
p[s[i]] = true;
}
if(f){
for(i = 0; i < 26; i++) p['A' + i] = true;
}
cin >> t; len = t.size();
if(s == ""){
cout << t << endl; return 0;
}
for(i = 0; i < len; i++){
if(!p[t[i]]) printf("%c", t[i]);
}
puts("");
return 0;
}
4、1034 有理数四则运算
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<bitset>
#include<queue>
#include<map>
//#include<unordered_map>
#include<stack>
#include<set>
#include<cmath>
#include<algorithm>
#include<vector>
#define ll long long
#define PI acos(-1.0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define esp 1e-5
#define lowbit(x) x & (-x)
using namespace std;
const int maxx = 6e6 + 5;
const int MaxN = 1e6;
const int inf = 0x3f3f3f3f;
const ll mod = 998244353;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int n, m, T;
ll a1, b1, a2, b2, a3, b3;
int a, b, c, d;
int l, r, ans;
void print(ll P, ll Q, int f){
ll AP, AQ;
if(!f && Q == 0){
printf("Inf");
return ;
}
if(P != 0){
if(Q < 0){
P *= -1; Q *= -1; }
ll gcd = __gcd(abs(P), abs(Q));
P /= gcd; Q /= gcd;
AP = P / Q, AQ = P % Q;
}else{
AP = AQ = 0;
}
if(f || (!f && a2 != 0)){
if(AP == 0 && AQ != 0){
if(P < 0) printf("(%lld/%lld)", P, Q);
else printf("%lld/%lld", P, Q);
}else if(AP != 0 && AQ == 0){
if(AP < 0) printf("(%lld)", AP);
else printf("%lld", AP);
}else if(AP != 0 && AQ != 0){
AQ = abs(AQ);
if(AP < 0) printf("(%lld %lld/%lld)", AP, AQ, Q);
else printf("%lld %lld/%lld", AP, AQ, Q);
}else printf("0");
}else if(!f && a2 == 0) printf("Inf");
}
int main(){
int i, j;
ll k;
while( scanf("%lld/%lld %lld/%lld", &a1, &b1, &a2, &b2) == 4){
k = b1 / __gcd(b1, b2) * b2;
print(a1, b1, 1); printf(" + "); print(a2, b2, 1); printf(" = "); print(k / b1 * a1 + k / b2 * a2, k, 1); puts("");
print(a1, b1, 1); printf(" - "); print(a2, b2, 1); printf(" = "); print(k / b1 * a1 - k / b2 * a2, k, 1); puts("");
print(a1, b1, 1); printf(" * "); print(a2, b2, 1); printf(" = "); print(a1 * a2, b1 * b2, 1); puts("");
print(a1, b1, 1); printf(" / "); print(a2, b2, 1); printf(" = "); print(a1 * b2, a2 * b1, 0); puts("");
}
return 0;
}
5、1035 插入与归并
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<bitset>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<algorithm>
#include<vector>
#define ll long long
#define PI acos(-1.0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define esp 1e-5
#define lowbit(x) x & (-x)
using namespace std;
const int maxx = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll mod = 998244353;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int n, m, T;
int l, r, cnt, tot;
int a[maxx + 5], b[maxx + 5];
int In[maxx + 5], Me[maxx + 5];
int check(){
int x = 0, y = 0;
for(int i = 0; i < n; i++){
if(In[i] == b[i]) x++;
else break;
}
if(x == n) return 1;
for(int i = 0; i < n; i++){
if(Me[i] == b[i]) y++;
else break;
}
if(y == n) return 2;
return 3;
}
int main(){
int i, j, k;
while(cin >> n){
for(i = 0; i < n; i++){
cin >> a[i];
In[i] = Me[i] = a[i];
}
for(i = 0; i < n; i++) cin >> b[i];
l = 0, r = 1, m = 0;
while(1){
l++; l = min(l, n);
sort(In, In + l);
for(i = 0; i < n; i += r){
int s = i, e = min(i + r, n);
sort(Me + s, Me + e);
}
r *= 2;
if(m == 1 || m == 2) break;
m = check();
}
if(m == 1){
cout << "Insertion Sort" << endl;
/*下面的特判(指while循环)不加会被测试点2卡
这是系统判定的问题 当输入
3
1 3 2
1 3 2
不加特判输出(按道理来说是没有问题的)
Insertion Sort
1 3 2
但是系统默认输出结果为
Insertion Sort
1 2 3
所以需要特判一下,即当输出序列与原序列不等才输出 */
while(check() == 1){
l++; l = min(l, n);
sort(In, In + l);
}
for(i = 0; i < n; i++)
printf("%d%c", In[i], i == n - 1 ? '\n' : ' ');
}
if(m == 2){
cout << "Merge Sort" << endl;
for(i = 0; i < n; i++)
printf("%d%c", Me[i], i == n - 1 ? '\n' : ' ');
}
}
return 0;
}
6、1036 跟奥巴马一起编程
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<bitset>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<algorithm>
#include<vector>
#define ll long long
#define PI acos(-1.0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define esp 1e-5
#define lowbit(x) x & (-x)
using namespace std;
const int maxx = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll mod = 998244353;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int n, m, T;
int l, r, cnt, tot;
int main(){
int i, j, k;
char ch;
while(cin >> n >> ch){
m = n / 2;
if(n & 1) m++;
for(i = 0; i < n; i++) printf("%c", ch); puts("");
for(i = 0; i < m - 2; i++){
printf("%c", ch);
for(j = 0; j < n - 2; j++) printf(" ");
printf("%c\n", ch);
}
for(i = 0; i < n; i++) printf("%c", ch); puts("");
}
return 0;
}
7、1037 在霍格沃茨找零钱
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<bitset>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<algorithm>
#include<vector>
#define ll long long
#define PI acos(-1.0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define esp 1e-5
#define lowbit(x) x & (-x)
using namespace std;
const int maxx = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll mod = 998244353;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int n, m, T;
int l, r, cnt, tot;
ll a, b, c;
ll A, B, C;
int main(){
int i, j, k;
while( scanf("%lld.%lld.%lld %lld.%lld.%lld", &a, &b, &c, &A, &B, &C) == 6){
a = c + 29 * b + 29 * 17 * a;
A = C + 29 * B + 29 * 17 * A;
a = A - a;
if(a < 0){
printf("-"); a = abs(a);
}
ll aA = a / (29 * 17);
ll bB = a % (29 * 17) / 29;
ll cC = a % (29 * 17) % 29;
printf("%lld.%lld.%lld\n", aA, bB, cC);
}
return 0;
}
8、1038 统计同成绩学生
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<bitset>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<algorithm>
#include<vector>
#define ll long long
#define PI acos(-1.0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define esp 1e-5
#define lowbit(x) x & (-x)
using namespace std;
const int maxx = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll mod = 998244353;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int n, m, T;
int l, r, cnt, tot;
int a[105];
int main(){
int i, j, k;
while(cin >> n){
for(i = 0; i < n; i++){
cin >> m; a[m]++;
}
cin >> m;
for(i = 0; i < m; i++){
cin >> k;
printf("%d%c", a[k], i == m - 1 ? '\n' : ' ');
}
}
return 0;
}
9、1039 到底买不买
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<bitset>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<algorithm>
#include<vector>
#define ll long long
#define PI acos(-1.0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define esp 1e-5
#define lowbit(x) x & (-x)
using namespace std;
const int maxx = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll mod = 998244353;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int n, m, T;
int l, r, cnt, tot;
string s, t;
map<char, int> p;
map<char, int>::iterator it;
int main(){
int i, j, k;
while(cin >> s >> t){
int lent = t.size();
for(i = 0; i < lent; i++) p[t[i]]++;
int lens = s.size();
for(i = 0; i < lens; i++){
if(p[s[i]]) p[s[i]]--;
}
bool ok = true;
for(it = p.begin(); it != p.end(); it++){
if(it -> se > 0){
m += it -> se; ok = false; }
}
if(ok) printf("Yes %d\n", lens - lent);
else printf("No %d\n", m);
}
return 0;
}
10、1040 有几个PAT
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<cmath>
#include<algorithm>
#include<vector>
#define ll long long
#define ld long double
#define PI acos(-1.0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define esp 1e-5
#define lowbit(x) x & (-x)
using namespace std;
const int maxx = 1e6 + 5;
const int MaxN = 1e6;
const int inf = 0x3f3f3f3f;
const double eps = 1e-5;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int n, m, T;
long long l, r, ans;
string s;
long long pre[maxx + 5], suf[maxx + 5];
int main(){
int i, j, k;
while( cin >> s){
int len = s.size(), cnt = 0;
for(i = 0; i < len; i++){
if(s[i] == 'P') cnt++;
pre[i] = cnt;
}
for(i = len - 1, cnt = 0; i >= 0; i--){
if(s[i] == 'T') cnt++;
suf[i] = cnt;
}
for(i = 0; i < len; i++){
if(s[i] == 'A') ans = (ans + pre[i] * suf[i] % mod) % mod;
}
printf("%lld\n", ans);
}
return 0;
}
2021/2/9完结(这个专题暂告一段落,之后的几天专心刷LeetCode上的题目吧,今天约了同学一起出去吃个饭,晚点回来补LeetCode)。