春节刷题day3:PAT
1021 个位数统计
1022 D进制的A+B
1023 组个最小数
1024 科学计数法
1025 反转链表
1026 程序运行时间
1027 打印沙漏
1028 人口普查
1029 旧键盘
1030 完美数列
1、1021 个位数统计
#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 a[10];
string s;
int main(){
int i, j, k;
while( cin >> s){
int len = s.size();
for(i = 0; i < len; i++) a[s[i] - '0']++;
for(i = 0; i < 10; i++)
if(a[i]){
printf("%d:%d\n", i, a[i]);
break;
}
for(j = i + 1; j < 10; j++)
if(a[j]) printf("%d:%d\n", j, a[j]);
}
return 0;
}
2、1022 D进制的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 100005
using namespace std;
int n, m, T;
string s;
long long a, b, c;
int main(){
int i, j, k;
while( cin >> a >> b >> c){
a += b;
if(!a){ //测试点3卡a = 0, b = 0;
cout << a << endl;
continue;
}
while(a){
s += a % c + '0'; a /= c;
}
reverse(s.begin(), s.end());
cout << s << endl;
}
return 0;
}
3、1023 组个最小数
#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 a[10];
int main(){
int i, j, k;
for(i = 0; i < 10; i++) cin >> a[i];
for(i = 1; i < 10; i++){
if(a[i]){
printf("%d", i); a[i]--; break;
}
}
for(i = 0; i < 10; i++){
for(j = 0; j < a[i]; j++) printf("%d", i);
}
puts("");
return 0;
}
4、1024 科学计数法
#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, ans;
string s, t, p, q;
int main(){
int i, j, k;
while( cin >> s){
int len = s.size();
if(s[0] == '-') printf("-");
int pos = s.find('E'); t = s.substr(pos + 2);
reverse(t.begin(), t.end()); int lent = t.size();
for(i = 0, k = 1; i < lent; i++){
r += (t[i] - '0') * k; k *= 10;
}
if(s[pos + 1] == '-'){
printf("0.");
for(i = 0; i < r - 1; i++) printf("0");
for(i = 1; i < pos; i++){
if(s[i] == '.') continue;
else printf("%c", s[i]);
}
}else{
if(pos - 4 >= r){
l = r + 3;
for(i = 1; i < pos; i++){
if(s[i] == '.') continue;
if(i == l) printf(".");
printf("%c", s[i]);
}
}else{
for(i = 1; i < pos; i++){
if(s[i] == '.') continue;
printf("%c", s[i]);
}
for(i = 0; i < r + 3 - pos; i++) printf("0");
}
}
puts("");
}
return 0;
}
5、1025 反转链表
#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
#define INF 0x7f7f7f7f
#define ull unsigned long long
using namespace std;
int N, M, T;
int L, K, tot;
map<int, int> p;
struct node{
int add, val, nxt;
}a[maxx + 5];
vector<node> v;
void slove(){
while(L != -1){
int idx = p[L];
v.push_back(a[idx]);
L = a[idx].nxt;
}
int tot = v.size();
for(int i = 0, cnt = 0; i < tot; i++){
cnt++;
if(cnt == K){
reverse(v.begin() + i + 1 - K, v.begin() + i + 1);
cnt = 0;
}
}
for(int i = 0; i < tot - 1; i++)
printf("%05d %d %05d\n", v[i].add, v[i].val, v[i + 1].add);
printf("%05d %d -1\n", v[tot - 1].add, v[tot - 1].val);
}
int main(){
int i, j;
while(cin >> L >> N >> K){
for(i = 0; i < N; i++){
cin >> a[i].add >> a[i].val >> a[i].nxt;
p[a[i].add] = i;
}
slove();
}
return 0;
}
6、1026 程序运行时间
#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 main(){
int i, j, k;
while(cin >> n >> m){
n = (m - n) * 1.0 / 100;
if( (m - n) % 100 >= 50) n++;
// n = ceil( (m - n) * 1.0 / 100);
int h = n / 3600;
int m = (n - h * 3600) / 60;
int s = (n - h * 3600 - m * 60);
printf("%02d:%02d:%02d\n", h, m, s);
}
return 0;
}
7、1027 打印沙漏
#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 cnt;
int main(){
int i, j, k;
char ch;
while(cin >> n >> ch){
n--;
for(i = 3; ; i += 2){
if(n < 2 * i) break;
n -= 2 * i; cnt++;
}
for(i = 0; i < cnt; i++){
for(j = 0; j < i; j++) printf(" ");
for(j = 0; j < 3 + 2 * (cnt - i - 1); j++)
printf("%c", ch);
puts("");
}
for(i = 0; i < cnt; i++) printf(" ");
printf("%c\n", ch);
for(i = 0; i < cnt; i++){
for(j = 0; j < cnt - i - 1; j++) printf(" ");
for(j = 0; j < 3 + 2 * i; j++)
printf("%c", ch);
puts("");
}
cout << n << endl;
}
return 0;
}
8、1028 人口普查
#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 cnt;
string Min = "1814/09/06";
string Max = "2014/09/06";
struct node{
string x, y;
bool operator < (const node &A)const{
return y < A.y;
}
}a[maxx + 5];
int main(){
int i, j, k;
while(cin >> n){
for(i = 0; i < n; i++){
string x, y;
cin >> x >> y;
if(y >= Min && y <= Max){
a[cnt].x = x; a[cnt++].y = y;
}
}
sort(a, a + cnt);
if(cnt) cout << cnt << " " << a[0].x << " " << a[cnt - 1].x << endl;
else cout << cnt << endl;
}
return 0;
}
9、1029 旧键盘
#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 cnt;
map<char, bool> p;
string s, t, ans;
int main(){
int i, j, k;
while(cin >> s >> t){
int lent = t.size();
int lens = s.size();
for(i = 0; i < lens; i++){
if(s[i] >= 'a' && s[i] <= 'z') s[i] = 'A' + s[i] - 'a';
}
for(i = 0; i < lent; i++){
if(t[i] >= 'a' && t[i <= 'z']) t[i] = 'A' + t[i] - 'a';
}
for(i = 0; i < lent; i++) p[t[i]] = true;
for(i = 0; i < lens; i++){
if(!p[s[i]]){
ans += s[i]; p[s[i]] = true;
}
}
cout << ans << endl;
}
return 0;
}
10、1030 完美数列
#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
#define INF 0x7f7f7f7f
using namespace std;
long long n, m, T;
long long a[maxx + 5];
int main(){
int i, j, k;
while(cin >> n >> m){
int ans = -1;
for(i = 0; i < n; i++) cin >> a[i];
sort(a, a + n); a[n] = INF;
for(i = 0; i < n; i++){
T = m * a[i];
k = upper_bound(a, a + n, T) - a;
ans = max(ans, k - i);
}
cout << ans << endl;
}
return 0;
}
2021/2/8完结(今天结束的稍微早点,刷题过程中主要是有些坑点让人头大,要是自己能够考虑全面就好了)。