本文主要是介绍春节刷题day2:[PAT乙级:1011 ~ 1020 ],希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
春节刷题day2:PAT
1011 A+B 和 C
1012 数字分类
1013 数素数
1014 福尔摩斯的约会
1015 德才论
1016 部分A+B
1017 A除以B
1018 锤子剪刀布
1019 数字黑洞
1020 月饼
1、1011 A+B 和 C
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<sstream>
#include<string>
#include<cstring>
#define fi first
#define se secondusing namespace std;int n, m, T, tot;
long long a, b, c;int main(){int i, j, k;cin >> T;for(i = 1; i <= T; i++){cin >> a >> b >> c;if(a + b > c) printf("Case #%d: true\n", i);else printf("Case #%d: false\n", i);}return 0;
}
2、1012 数字分类
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<sstream>
#include<string>
#include<cstring>
#define fi first
#define se secondusing namespace std;int n, m, T, tot;
int ans[10];
bool f;int main(){int i, j, k;while( cin >> n){f = true;for(i = 0; i < n; i++){cin >> k;if(k % 5 == 0 && (k & 1) == 0) ans[0] += k;if(k % 5 == 1){tot++;if(f) ans[1] += k;else ans[1] -= k;f = !f;}if(k % 5 == 2) ans[2]++;if(k % 5 == 3){ ans[3] += k; m++; }if(k % 5 == 4) ans[4] = max(ans[4], k);}if(ans[0]) printf("%d", ans[0]);else printf("N");if(tot) printf(" %d", ans[1]);else printf(" N");if(ans[2]) printf(" %d", ans[2]);else printf(" N");if(ans[3]) printf(" %.1f", ans[3] * 1.0 / m);else printf(" N");if(ans[4]) printf(" %d\n", ans[4]);else printf(" N\n");}return 0;
}
3、1013 数素数
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<sstream>
#include<string>
#include<cstring>
#define fi first
#define se second
#define maxx 1000005
using namespace std;int n, m, T, tot;
int ans[maxx + 5], prime[maxx + 5];
bool Is_prime[maxx + 5];void init(){memset(Is_prime, 1, sizeof Is_prime);for(int i = 2; i <= maxx; i++){if(Is_prime[i]) prime[tot++] = i;for(int j = 0; j < tot; j++){if(i * prime[j] >= maxx) break;Is_prime[i * prime[j]] = 0;if(i % prime[j] == 0) break;}}
}int main(){int i, j, k;init();while(cin >> n >> m){for(i = n - 1, k = 0; i < m; i++){printf("%d", prime[i]);k++;if(k == 10){ puts(""); k = 0; }else{if(i != m - 1) printf(" ");else printf("\n");}}}return 0;
}
4、1014 福尔摩斯的约会
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<sstream>
#include<string>
#include<cstring>
#define fi first
#define se second
#define maxx 1000005
using namespace std;int n, m, T, tot;
map<char, string> day;
map<char, int> hh;
string s1, s2, s3, s4;void init(){day['A'] = "MON"; day['B'] = "TUE"; day['C'] = "WED";day['D'] = "THU"; day['E'] = "FRI"; day['F'] = "SAT";day['G'] = "SUN";for(int i = 0; i < 10; i++) hh['0' + i] = i;for(int i = 0; i < 14; i++) hh['A' + i] = 10 + i;
}int main(){int i, j, k;init();while(cin >> s1 >> s2 >> s3 >> s4){int f = 1;int len1 = min(s1.size(), s2.size());int len2 = min(s3.size(), s4.size());for(i = 0; i < len1; i++){if(s1[i] == s2[i]){if(f == 1 && s1[i] >= 'A' && s1[i] <= 'G'){cout << day[s1[i]] << " "; f++; }else if(f == 2 && ( (s1[i] >= '0' && s1[i] <= '9') || (s1[i] >= 'A' && s1[i] <= 'N'))){printf("%02d:", hh[s1[i]]); f++; }}}for(i = 0; i < len2; i++){if(s3[i] == s4[i] && ( (s3[i] >= 'A' && s3[i] <= 'Z') || (s3[i] >= 'a' && s3[i] <= 'z'))){ printf("%02d\n", i); break; }}}return 0;
}
5、1015 德才论
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<sstream>
#include<string>
#include<cstring>
#define fi first
#define se second
#define maxx 100005
using namespace std;int N, L, H;
int tota, totb, totc, totd;
struct node{string num;int x, y, all;bool operator < (const node &A)const{if(all == A.all){if(x == A.x){return num < A.num;}else return x > A.x;}else return all > A.all;}
}a[maxx + 5], b[maxx + 5], c[maxx + 5], d[maxx + 5];int main(){int i, j, k;while(cin >> N >> L >> H){node now;for(i = 0; i < N; i++){cin >> now.num >> now.x >> now.y;now.all = now.x + now.y;if(now.x >= L && now.y >= L){if(now.x >= H && now.y >= H) a[tota++] = now;else if(now.x >= H && now.y < H) b[totb++] = now;else if(now.x >= now.y) c[totc++] = now;else d[totd++] = now;}}sort(a, a + tota);sort(b, b + totb);sort(c, c + totc);sort(d, d + totd);cout << tota + totb + totc + totd << endl;for(i = 0; i < tota; i++) cout << a[i].num << " " << a[i].x << " " << a[i].y << endl;for(i = 0; i < totb; i++) cout << b[i].num << " " << b[i].x << " " << b[i].y << endl;for(i = 0; i < totc; i++) cout << c[i].num << " " << c[i].x << " " << c[i].y << endl;for(i = 0; i < totd; i++) cout << d[i].num << " " << d[i].x << " " << d[i].y << endl;}return 0;
}
6、1016 部分A+B
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<sstream>
#include<string>
#include<cstring>
#define fi first
#define se second
#define maxx 1000005
using namespace std;long long n, m, ans;long long slove(){long long res = 0;while(n){if(n % 10 == m){ res = res * 10 + m; }n /= 10;}return res;
}int main(){int i, j, k;while( cin >> n >> m){ans += slove();cin >> n >> m;ans += slove();cout << ans << endl;}return 0;
}
7、1017 A除以B
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<sstream>
#include<string>
#include<cstring>
#define fi first
#define se second
#define maxx 1000005
using namespace std;int n, m, T;
string s, ans;void slove(){bool f = true;int a = 0;int len = s.size();for(int i = 0; i < len; i++){a = a * 10 + (s[i] - '0');if(f){if(a >= n){ ans += (a / n + '0'); a %= n; }f = false;}else{ans += (a / n + '0'); a %= n;}}if(ans == "") cout << "0 " << a << endl;else cout << ans << " " << a << endl;
}int main(){int i, j, k;while(cin >> s >> n){slove();}return 0;
}
8、1018 锤子剪刀布
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<sstream>
#include<string>
#include<cstring>
#define fi first
#define se second
#define maxx 100005
using namespace std;int n, m, T;
int ans1, ans2, ans3;
char a[maxx + 5], b[maxx + 5];
struct node{char ch;int num;bool operator < (const node &A)const{if(num == A.num) return ch < A.ch;return num > A.num;}
}A[3], B[3];void slove(char x, char y){if(x == 'C'){if(y == 'J'){ A[1].num++; ans1++; }else if(y == 'C') ans2++;else{ B[0].num++; ans3++; }}else if(x == 'J'){if(y == 'B'){ A[2].num++; ans1++; }else if(y == 'J') ans2++;else{ B[1].num++; ans3++; }}else{if(y == 'C'){ A[0].num++; ans1++; }else if(y == 'B') ans2++;else{ B[2].num++; ans3++; }}
}int main(){int i, j, k;while(cin >> n){for(i = 0; i < n; i++){cin >> a[i] >> b[i];slove(a[i], b[i]);}cout << ans1 << " " << ans2 << " " << ans3 << endl;cout << ans3 << " " << ans2 << " " << ans1 << endl;A[0].ch = B[0].ch = 'B';A[1].ch = B[1].ch = 'C';A[2].ch = B[2].ch = 'J';sort(A, A + 3); sort(B, B + 3);cout << A[0].ch << " " << B[0].ch << endl;}return 0;
}
9、1019 数字黑洞
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<sstream>
#include<string>
#include<cstring>
#define fi first
#define se second
#define maxx 100005
using namespace std;int n, m, T;
string a, b, c, s;
bool cmp(char a, char b){return a > b;
}int main(){int i, j, k;while(cin >> n){while(1){a = to_string(n);k = log10(n) + 1;a.insert(a.size(), 4 - k, '0'); b = a;sort(a.begin(), a.end(), cmp);sort(b.begin(), b.end());c = to_string(stoi(a) - stoi(b));printf("%04d - %04d = %04d\n", stoi(a), stoi(b), stoi(c));if(stoi(a) == stoi(b) || stoi(c) == 6174) break;n = stoi(c);}}return 0;
}
10、1020 月饼
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<sstream>
#include<string>
#include<cstring>
#define fi first
#define se second
#define maxx 100005
using namespace std;int n, m, T;
struct node{double x, y;double val;bool operator < (const node &A)const{return val > A.val;}
}a[1005];
double ans;int main(){int i, j, k;while(cin >> n >> m){for(i = 0; i < n; i++) cin >> a[i].x;for(i = 0; i < n; i++) cin >> a[i].y;for(i = 0; i < n; i++) a[i].val = a[i].y * 1.0 / a[i].x;sort(a, a + n);for(i = 0; i < n; i++){if(a[i].x <= m){ans += a[i].y; m -= a[i].x;}else{ans += a[i].val * m; m = 0; break;}}printf("%.2f\n", ans);}return 0;
}
2021/2/7完结(今天PAT提前完成,有空刷刷LeetCode)。
这篇关于春节刷题day2:[PAT乙级:1011 ~ 1020 ]的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!