#include<cstdio>#include<algorithm>#include<iostream>#include<cmath>#include<vector>usingnamespace std;intmain(){int N, max =-1;scanf("%d",&N);
vector<int> a, b, ans;
a.resize(N);
b.resize(N);for(int i =0; i < N; i++){scanf("%d",&a[i]);
b[i]= a[i];}sort(a.begin(), a.end());for(int i =0; i < N; i++){if(max < b[i]){
max = b[i];}if(a[i]== b[i]&& b[i]>= max)
ans.push_back(a[i]);}int m = ans.size();printf("%d\n", m);for(int i =0; i<m;i++){printf("%d", ans[i]);if(i < m-1)printf(" ");}printf("\n");return0;}
1059 Prime Factors
//质因子分解 素数筛选法#include<cstdio>#include<algorithm>#include<iostream>#include<cmath>usingnamespace std;constint maxn =100010;int prime[maxn], pNum =0;bool p[maxn]={0};//bool is_prime(int n)//{// if(n == 1)// return false;// int sqr = (int)sqrt(1.0 * n);// for(int i = 2; i <= sqr; i++)// {// if(n % i == 0)// return false;// } // return true;//}////void Find_Prime()//{// for(int i = 1; i < maxn; i++)// {// if(is_prime(i) == true)// {// prime[pNum++] = i;// }// }//}voidFind_prime(){for(int i =2; i < maxn; i++){if(p[i]==false){
prime[pNum++]= i;for(int j = i + i; j < maxn; j += i){
p[j]=true;}}}}struct factor
{int x, cnt;}fac[10];intmain(){Find_prime();int n, num =0;scanf("%d",&n);if(n ==1)printf("1=1");else{printf("%d=", n);int sqr =(int)sqrt(1.0*n);for(int i =0; i < pNum && prime[i]<= sqr; i++){if(n % prime[i]==0){
fac[num].x = prime[i];
fac[num].cnt =0;while(n % prime[i]==0){
fac[num].cnt++;
n /= prime[i];}
num++;}if(n ==1)break;}if(n !=1){
fac[num].x = n;
fac[num++].cnt =1;}for(int i =0; i < num; i++){if(i >0)printf("*");printf("%d", fac[i].x);if(fac[i].cnt >1){printf("^%d",fac[i].cnt);}}}return0;}
#include<cstdio>#include<algorithm>#include<iostream>#include<cmath>usingnamespace std;int num[5];int zheng[5];int ni[5];boolcmp(int a,int b){return a > b;}voidto_array(int n,int num[]){for(int i =0; i <4; i++){
num[i]= n %10;
n /=10;}}intto_number(int num[]){int N =0;int k =1;for(int i =3; i >=0; i--){
N += num[i]*k;
k *=10;}return N;}intmain(){int N, MAX, MIN;scanf("%d",&N);while(1){to_array(N, num);sort(num, num +4);
MIN =to_number(num);sort(num, num +4, cmp);
MAX =to_number(num);
N = MAX - MIN;printf("%04d - %04d = %04d\n", MAX ,MIN ,N);if(N ==0|| N ==6174)break;}return0;}
A 1093 Count PAT’s
#include<cstdio>#include<algorithm>#include<iostream>#include<cmath>#include<cstring>usingnamespace std;constint MAXN =100010;constint MOD =1000000007;char str[MAXN];int leftNumP[MAXN]={0};intmain(){
cin.getline(str,MAXN);int len =strlen(str);for(int i =0; i < len; i++){if(i >0){
leftNumP[i]= leftNumP[i -1];}if(str[i]=='P'){
leftNumP[i]++;}}int ans =0, rightNumT =0;for(int i = len -1; i >=0;i--){if(str[i]=='T'){
rightNumT++;}elseif(str[i]=='A'){
ans =(ans + leftNumP[i]* rightNumT)% MOD;}}printf("%d\n", ans);return0;}
二 乙级
1013 数素数
#include<cstdio>#include<algorithm>#include<iostream>#include<cmath>usingnamespace std;constint maxn =1010000;int prime[maxn],pNum =0;bool p[maxn]={0};voidFind_Prime(int n){for(int i =2; i < maxn; i++){if(p[i]==false){
prime[pNum++]= i;if(pNum >= n)break;for(int j = i + i; j < maxn; j += i){
p[j]=true;}}}}intmain(){int m, n, count =0;scanf("%d%d",&m,&n);Find_Prime(n);for(int i = m; i <= n; i++){printf("%d", prime[i -1]);
count++;if(count %10!=0&& i < n)printf(" ");elseprintf("\n");}return0;}
1019 数字黑洞
#include<cstdio>#include<algorithm>#include<iostream>#include<cmath>usingnamespace std;int num[5];int zheng[5];int ni[5];boolcmp(int a,int b){return a > b;}voidto_array(int n,int num[]){for(int i =0; i <4; i++){
num[i]= n %10;
n /=10;}}intto_number(int num[]){int N =0;int k =1;for(int i =3; i >=0; i--){
N += num[i]*k;
k *=10;}return N;}intmain(){int N, MAX, MIN;scanf("%d",&N);while(1){to_array(N, num);sort(num, num +4);
MIN =to_number(num);sort(num, num +4, cmp);
MAX =to_number(num);
N = MAX - MIN;printf("%04d - %04d = %04d\n", MAX ,MIN ,N);if(N ==0|| N ==6174)break;}return0;}