PAT b1041-b1045题解
来源:互联网 发布:淘宝官网电脑版 编辑:程序博客网 时间:2024/05/16 19:12
1、b1041
#include <cstdio>const int MAXN = 1005;struct Stu{long long num1;int num2;int num3;}stu[MAXN];int main(){int n;scanf("%d", &n);for(int i = 0; i < n; i++){long long n1;int n2, n3;scanf("%lld%d%d", &n1, &n2, &n3);stu[i].num1 = n1;stu[i].num2 = n2;stu[i].num3 = n3;}int k;scanf("%d", &k);for(int i = 0; i < k; i++){int n2;scanf("%d", &n2);for(int i = 0; i < 1001; i++){if(stu[i].num2 == n2){printf("%lld %d\n", stu[i].num1, stu[i].num3);}}}return 0;}
2、b1042
#include <cstdio>#include <cstring>const int maxn = 1010;char str[maxn];int hashTable[30] = {0};int main(){gets(str);int len = strlen(str);for(int i = 0; i < len; i++){if(str[i] >= 'a' && str[i] <= 'z'){hashTable[str[i] - 'a']++;}else if(str[i] >= 'A' && str[i] <= 'Z'){hashTable[str[i] - 'A']++; }}int k = 0;for(int i = 0; i < 26; i++){if(hashTable[i] > hashTable[k]){k = i;}}printf("%c %d\n", 'a' + k, hashTable[k]);return 0;}
3、b1043
#include <cstdio>#include <cstring>int hashTable[128] = {0};char str[10010];int main(){gets(str);int len = strlen(str);for(int i = 0; i < len; i++){hashTable[str[i]]++;}for(int i = 0; i < 10010; i++){if(hashTable['P'] != 0){printf("P");hashTable['P']--; }if(hashTable['A'] != 0){printf("A");hashTable['A']--;}if(hashTable['T'] != 0){printf("T");hashTable['T']--;}if(hashTable['e'] != 0){printf("e");hashTable['e']--;}if(hashTable['s'] != 0){printf("s");hashTable['s']--;}if(hashTable['t'] != 0){printf("t");hashTable['t']--;}}return 0;}
4、b1044
#include <cstdio>#include <iostream> #include <string>#include <map>using namespace std;string unitDigit[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};string tenDigit[13] = {"tret", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};string numToStr[170];map<string, int> strToNum;void init(){for(int i = 0; i < 13; i++){numToStr[i] = unitDigit[i];strToNum[unitDigit[i]] = i;numToStr[i * 13] = tenDigit[i];strToNum[tenDigit[i]] = i * 13; }for(int i = 1; i < 13; i++){for(int j = 1; j < 13; j++){string str = tenDigit[i] + " " + unitDigit[j];numToStr[i * 13 + j] = str;strToNum[str] = i * 13 + j;}}} int main(){init();int T;scanf("%d%*c", &T);while(T--){string str;getline(cin, str);if(str[0] >= '0' && str[0] <= '9'){int num = 0;for(int i = 0; i < str.length(); i++){num = num * 10 + (str[i] - '0');}cout << numToStr[num] << endl;}else{cout << strToNum[str] << endl;}} return 0;}
5、b1045
#include <cstdio>#include <algorithm>using namespace std;const int MAXN = 100010;const int INF = 0x3fffffff;int a[MAXN], leftMax[MAXN], rightMin[MAXN];int ans[MAXN], num = 0;int main(){int n;scanf("%d", &n);for(int i = 0; i < n; i++){scanf("%d", &a[i]);}leftMax[0] = 0;for(int i = 0; i < n; i++){leftMax[i] = max(leftMax[i - 1], a[i - 1]);}rightMin[n - 1] = INF;for(int i = n - 2; i >= 0; i--){rightMin[i] = min(rightMin[i + 1], a[i + 1]);}for(int i = 0; i < n; i++){if(leftMax[i] < a[i] && rightMin[i] > a[i]){ans[num++] = a[i];}}printf("%d\n", num);for(int i = 0; i < num; i++){printf("%d", ans[i]);if(i < num - 1) printf(" ");}printf("\n");return 0;}
阅读全文
1 0
- PAT b1041-b1045题解
- [PAT] B1041
- PAT B1041
- PAT B1045
- 浙大 PAT b1041
- 浙大 PAT b1045
- PAT-B1045. 快速排序
- PAT B1045. 快速排序
- 数学问题--PAT.B1045 & A1101.
- PAT B1045. 快速排序(25)
- PAT B1041. 考试座位号
- PAT乙级练习题B1041. 考试座位号
- PAT乙级练习题B1045. 快速排序
- PAT---B1041. 考试座位号(15)
- PAT B1041. 考试座位号(15)
- PAT 1001-1010 题解
- PAT 1011-1020 题解
- PAT 1021-1030 题解
- 22.系统广播-短信
- Java经典排序算法之冒泡排序
- 思绪整理
- sql
- php yii伪静态
- PAT b1041-b1045题解
- Raspberry上手指南(2)
- 将spring3源码导入进eclipse
- javascript中"[]"与"."的关系
- 关于Android的一些布局
- 关于maven在idea上的配置问题
- 十一天
- Vue.js computed vs Methods区别
- Python入门学习之While