本文主要是介绍春节刷题day1:[PAT乙级:1001 ~ 1010 ],希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
春节刷题day1:PAT
1001 害死人不偿命的(3n+1)猜想
1002 写出这个数
1003 我要通过!
1004 成绩排名
1005 继续(3n+1)猜想
1006 换个格式输出整数
1007 素数对猜想
1008 数组元素循环右移问题
1009 说反话
1010 一元多项式求导
1、1001 害死人不偿命的(3n+1)猜想
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#include<cstring>using namespace std;int n, m, T;int main(){int i, j, k;while(cin >> n){int ans = 0;while(n != 1){if(n & 1) n = (3 * n + 1) / 2;else n /= 2;ans++;}cout << ans << endl;}return 0;
}
2、1002 写出这个数
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#include<cstring>using namespace std;int n, m, T, tot;
string s, ans[15];
map<int, string> p;void init(){p[0] = "ling"; p[1] = "yi"; p[2] = "er"; p[3] = "san";p[4] = "si"; p[5] = "wu"; p[6] = "liu"; p[7] = "qi";p[8] = "ba"; p[9] = "jiu";
}int main(){int i, j, k;init();while(cin >> s){int len = s.size(), sum = 0;for(i = 0; i < len; i++) sum += s[i] - '0';while(sum){ans[tot++] = p[sum % 10];sum /= 10;}reverse(ans, ans + tot);for(i = 0; i < tot; i++){cout << ans[i];printf("%c", i == tot - 1 ? '\n' : ' ');}}return 0;
}
3、1003 我要通过!
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#include<cstring>using namespace std;int n, m, T, len;
string s;bool checka(){for(int i = 0; i < len; i++){if(s[i] != 'P' && s[i] != 'A' && s[i] != 'T') return false;}return true;
}bool checkb(){int l, r, num = 0;for(int i = 0; i < len; i++)if(s[i] == 'P'){ l = i; break; }for(int i = len - 1; i >= 0; i--)if(s[i] == 'T'){ r = i; break; }for(int i = 0; i < len; i++) if(s[i] == 'A') num++;if((num != len - 2) || (len - 2 == 0)) return false;if((r - l - 1) * l != len - r - 1) return false;return true;
}int main(){int i, j, k;cin >> T;while( T-- ){cin >> s; len = s.size();if(checka() && checkb()) puts("YES");else puts("NO");}return 0;
}
4、1004 成绩排名
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#include<cstring>using namespace std;int n, m, T, len;struct node{string name;string num;int score;bool operator < (const node &A)const{return score < A.score;}
}a[10005];int main(){int i, j, k;while( cin >> n){for(i = 0; i < n; i++){cin >> a[i].name >> a[i].num >> a[i].score;}sort(a, a + n);cout << a[n - 1].name << " " << a[n - 1].num << endl;cout << a[0].name << " " << a[0].num << endl;}return 0;
}
5、1005 继续(3n+1)猜想
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#include<cstring>
#define fi first
#define se secondusing namespace std;int n, m, T, tot;
map<int, int> p;
map<int, int>::iterator it;
int ans[105];int main(){int i, j, k;while( cin >> n){for(i = 0; i < n; i++){cin >> m;p[m] = 1;}for(it = p.begin(); it != p.end(); it++){k = it -> fi;while(k != 1){if(p[k]) p[k]++;if(k & 1) k = (3 * k + 1) / 2;else k /= 2;}}for(it = p.begin(); it != p.end(); it++){if(it -> se == 2) ans[tot++] = it -> fi;}sort(ans, ans + tot, greater<int>());for(i = 0; i < tot; i++)printf("%d%c", ans[i] , i == tot - 1 ? '\n' : ' ');}return 0;
}
6、1006 换个格式输出整数
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#include<cstring>
#define fi first
#define se secondusing namespace std;int n, m, T, tot;
string s;int main(){int i, j, k;while( cin >> n){for(i = 0; i < n / 100; i++) printf("B");for(i = 0; i < n % 100 / 10; i++) printf("S");for(i = 1; i <= n % 10; i++) printf("%d", i);puts("");}return 0;
}
7、1007 素数对猜想
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#include<cstring>
#define fi first
#define se secondusing namespace std;int n, m, T, tot;
int prime[100005];bool check(int x){for(int i = 2; i <= sqrt(x); i++)if(x % i == 0) return false;return true;
}int main(){int i, j, k;for(i = 2; i <= 100005; i++){ if(check(i) ) prime[tot++] = i;}while(cin >> n){int ans = 0;for(i = 1; prime[i] <= n; i++){if(prime[i] - prime[i - 1] == 2) ans++;}cout << ans << endl;}return 0;
}
8、1008 数组元素循环右移问题
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#include<cstring>
#define fi first
#define se secondusing namespace std;int n, m, T, tot;
vector<int> v;int main(){int i, j, k;while(cin >> n >> m){for(i = 0; i < n; i++){cin >> k; v.push_back(k);}m %= n;if(m){printf("%d", v[n - m]);for(i = n - m + 1; i < n; i++) printf(" %d", v[i]);for(i = 0; i < n - m; i++) printf(" %d", v[i]);}else{printf("%d", v[0]);for(i = 1; i < n; i++) printf(" %d", v[i]);}puts("");}return 0;
}
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#include<cstring>
#define fi first
#define se secondusing namespace std;int n, m, T, tot;
int a[105];
vector<int> v;int main(){int i, j, k;while(cin >> n >> m){for(i = 0; i < n; i++){cin >> k; v.push_back(k);}m %= n;reverse(v.begin() + n - m, v.end());reverse(v.begin(), v.begin() + n - m);reverse(v.begin(), v.end());for(i = 0; i < n; i++)printf("%d%c", v[i], i == n - 1 ? '\n' : ' ');}return 0;
}
9、1009 说反话
#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;
string s, ans[105];int main(){int i, j, k;while( getline(cin, s)){string x;stringstream ss(s);while(ss >> x) ans[tot++] = x;for(i = tot - 1; i >= 0; i--){cout << ans[i];printf("%c", i == 0 ? '\n' : ' ');}}return 0;
}
10、1010 一元多项式求导
#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 a[10005], b[10005];int main(){int i, j, k;bool ok = false;for(i = 0; ; i++){cin >> a[i] >> b[i];if(b[i] == 0) break;a[i] *= b[i]; b[i] -= 1; ok = true;}for(j = 0; j < i; j++)printf("%d %d%c", a[j], b[j], j == i - 1 ? '\n' : ' ');if(!ok) printf("0 0\n");return 0;
}
2021/2/6完结(好久没写题了,写起来还是有点手生,今天刚刚放假,就先写这10道题吧,等之后有空争取每天多刷几道题吧)。
这篇关于春节刷题day1:[PAT乙级:1001 ~ 1010 ]的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!