PAT甲级
qq_2918
这个作者很懒,什么都没留下…
展开
-
PAT-A1121
#include#includeusing namespace std;int peo[100010]={0};int main(){int i, n, a, b, m;scanf("%d",&n);for(i=0;i<n;i++){ scanf("%d%d",&a,&b); peo[a]=b; peo[b]=a;}scanf("%d",&m);set st, temp;原创 2017-03-08 20:07:22 · 419 阅读 · 0 评论 -
PAT-A1120
#include#includeusing namespace std;int cal(int x){ int sum=0; while(x>0){ sum+=x%10; x/=10; } return sum;}int main(){int i, n, t;setst; scanf("%d",&n);for(i=0;i<n;i++){ scanf("%d",&原创 2017-03-08 20:07:05 · 353 阅读 · 0 评论 -
PAT-A1117
#includeint day[1000010]={0}, day1[1000010]={0};int main(){int i, n, max=0, temp, pre=1000005, sum=0, result=0;scanf("%d",&n);for(i=0;i<n;i++){ scanf("%d",&temp); day[temp]++; if(temp>max)max原创 2017-03-08 20:04:42 · 386 阅读 · 0 评论 -
PAT-A1116
#include#includeint flag[10010]={0};bool check(int k){ int i, sqr=(int)sqrt(double(k)); for(i=2;i<=sqr;i++){ if(k%i==0)return false; } return true;}int main(){int i, n, k, rank=1, temp;sc原创 2017-03-08 20:04:26 · 429 阅读 · 0 评论 -
PAT-A1113
#include#includeusing namespace std;int d[100010];int main(){int i,n, sum1=0, sum2=0;scanf("%d",&n);for(i=0;i<n;i++){ scanf("%d",&d[i]);}sort(d,d+n);for(i=0;i<n/2;i++){ sum1+=d[i];}for(i原创 2017-03-08 20:04:04 · 295 阅读 · 0 评论 -
PAT-A1115
#include#includeusing namespace std;struct pnode{ int data; pnode* left; pnode* right; int level; pnode():left(NULL),right(NULL){}};int num_last=0, num_second=0, maxlevel=0;void insert(pnod原创 2017-03-08 20:02:58 · 79 阅读 · 0 评论 -
PAT-A1111
#include#include#include#includeusing namespace std;const int MAXV=510;const int INF=1000000000;int n, m, from, to;int G[MAXV][MAXV], Time[MAXV][MAXV];int d[MAXV], t[MAXV];bool vis[MAXV]={fa原创 2017-03-08 20:02:54 · 274 阅读 · 0 评论 -
PAT-A1110
#include#include#includeusing namespace std;struct pnode{ int left, right; pnode():left(-1),right(-1){}}node[25];int father[25];int main(){int i, n, id, root, count=0, last=0;char t1[5], t2原创 2017-03-08 20:02:20 · 350 阅读 · 0 评论 -
PAT-A1108
#include#include#includeusing namespace std;bool check(char str[]){ int i, diancount=0, len=strlen(str); for(i=0;i<len;i++){ if(str[i]=='-')continue; if(str[i]=='.'){ diancount++; if(d原创 2017-03-08 19:54:20 · 928 阅读 · 0 评论 -
PAT-A1107
#include#includeusing namespace std;int hobby[1010]={0}, father[1010]={0}, num[1010]={0};bool cmp(int a,int b){ return a>b;}int find_father(int x){ int temp=x; while(father[x]!=x){ x=father原创 2017-03-08 19:54:05 · 523 阅读 · 0 评论 -
PAT-A1104
#includeint main(){int i, j, n;double ans=0,d[100010]={0};scanf("%d",&n);for(i=1;i<=n;i++){ scanf("%lf",&d[i]); ans=ans+d[i]*i*(n-i+1); }printf("%0.2f\n",ans);return 0;}原创 2017-03-08 19:53:43 · 310 阅读 · 0 评论 -
PAT-A1109
#include#include#includeusing namespace std;struct people{ char name[15]; int height;}peo[10010];bool cmp(people a , people b){ if(a.height!=b.height) return a.height>b.height; else return s原创 2017-03-08 19:53:18 · 462 阅读 · 0 评论 -
PAT-A1106
#include#include#includeusing namespace std;int n, min_level=110000, num=0;double p, r;struct pnode{ vector child;}node[100010];void DFSorder(int root, int depth){ if(node[root].child.size(原创 2017-03-08 19:52:41 · 418 阅读 · 0 评论 -
PAT-A1103
#include#includeusing namespace std;int n, k, p, max_facsum=-1;vector fac, temp, ans;int get_p(int a){ int loop=0, ans=1; while(loop<p){ans=ans*a; loop++;} return ans;}void DFS(int index, in原创 2017-03-08 19:52:25 · 436 阅读 · 0 评论 -
PAT-A1102
#include#includeusing namespace std;int n, sum=0;bool have_root[15]={false};struct pnode{ int left, right;}node[15];int check(char a){ if(a=='-')return -1; else {have_root[a-'0']=true;return原创 2017-03-08 19:51:54 · 291 阅读 · 0 评论 -
PAT-A1101
#include#includeusing namespace std;int a[100010]={0},maxx[100010]={0},minn[100010]={0},ans[100010]={0};int main(){int i, n, max=0, min=1000000000;scanf("%d",&n);for(i=0;i<n;i++){ scanf("%d",&原创 2017-03-08 19:51:32 · 367 阅读 · 0 评论 -
PAT-A1100
#include#include#include#includeusing namespace std;string aaa[13]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};string bbb[13]={"tret","tam","hel","maa","huh"原创 2017-03-08 19:47:54 · 249 阅读 · 0 评论 -
PAT-A1098
#include#includeusing namespace std;int n, orign[111]={0}, orign1[111]={0}, result[111]={0};bool cmp(int a[], int b[]){ for(int i=1;i<=n;i++){ if(a[i]!=b[i])return false; } return true;}v原创 2017-03-08 19:40:19 · 391 阅读 · 0 评论 -
PAT-A1099
#include#include#includeusing namespace std;int n, index=0, number[110]={0}, sum=0;struct pnode{ int data; int left, right;}node[110];void inorder(int root){ if(node[root].left!=-1)inorder(n原创 2017-03-07 21:09:11 · 77 阅读 · 0 评论 -
PAT-A1096
#include#includeint main(){int i, j, sqr, len, maxstart=-1, maxlen=0;long long temp, n;scanf("%lld",&n);sqr=sqrt(n*1.0);for(i=2;i<=sqr;i++){ temp=1; len=0; for(j=i;j<=sqr;j++){ temp*=j;原创 2017-03-07 21:09:21 · 273 阅读 · 0 评论 -
PAT-A1097
#include#includeusing namespace std;struct pnode{ int address; int data; int next;}node[100010];int flag[10010]={0},ans_in[100010]={-1},ans_not[100010]={-1};int main(){int i, head, n, p, tp原创 2017-03-07 21:09:09 · 246 阅读 · 0 评论 -
PAT-A1093
#include#include#includeusing namespace std;int main(){char c[100010];int i, len, nump[100010]={0},numt[100010]={0};long long ans=0;scanf("%s",c);len=strlen(c);for(i=1;i<=len;i++){ if(c[i-原创 2017-03-07 21:06:57 · 73 阅读 · 0 评论 -
PAT-A1094
#include#includeusing namespace std;struct pnode{ vector child;}node[110];int depth_num[110]={0}, max_num=-1, level;void DFS(int root, int depth){ depth_num[depth]++; if(depth_num[depth]>max_原创 2017-03-07 21:06:51 · 302 阅读 · 0 评论 -
PAT-A1118
#include#include#includeusing namespace std;int n, Q, sum=0;int father[10010];bool isfather[10010]={false};set st;int findfather(int x){ int a=x, aa; while(father[x]!=x){ x=father[x]; }原创 2017-03-08 20:03:29 · 298 阅读 · 0 评论 -
PAT-A1124
#include#include#include#includeusing namespace std;int m, n, s;vector ve;map mp;int main(){int i;string temp;bool flag=false;//flag表示是否输出过数据cin>>m>>n>>s;getchar();for(i=0;i<m;i++){ ci原创 2017-03-09 12:47:01 · 218 阅读 · 0 评论 -
PAT-A1125
前几天去刷了PAT,趁热把答案记录下来供大家参考这题完全是英语阅读题,题目读懂就能写题意:两根绳子打结之后长度会变成原来绳长的一般,且向下取整一维数组加sort函数搞定#include#includeusing namespace std;int rope[10010];int main(){int i, n, sum;scanf("%d",&n);for(i=0原创 2017-03-09 13:03:51 · 291 阅读 · 0 评论 -
PAT-A1126
前几天去刷了PAT,趁热把答案记录下来供大家参考这题完全是英语阅读题,题目读懂就能写我考试的时候花了起码10分钟去读题,英语实在太渣第3个测试点是个坑点,考的时候提交了11次才出来第3个测试点:关键字:connected graph,要先判断图是否是一个连通图#include#includeusing namespace std;const int INF=1原创 2017-03-09 13:38:39 · 742 阅读 · 0 评论 -
PAT-A1127
前几天去刷了PAT,趁热把答案记录下来供大家参考这题完全是英语阅读题,题目读懂就能写题意:BST,给中序序列和后序序列,重建这颗树,并将树按"Z"字型输出#include#include#includeusing namespace std;int n;int in[40], post[40];struct node{ int data; int level;原创 2017-03-09 13:40:33 · 914 阅读 · 0 评论 -
PAT-A1016
#include#include#includeusing namespace std;int fee[25]={0};struct record{ char name[25]; int mon, day,hour,minute; char state[10];}cord[1010];bool cmp(record a, record b){ if(strcmp(a.name原创 2017-03-06 11:36:54 · 912 阅读 · 0 评论 -
PAT-A1013
#include#include#includeusing namespace std;int n, m, k, current;vector gg[1010];bool visited[1010];void DFS(int k){ if(k==current)return ; visited[k]=true; for(int i=0;i<gg[k].size();i++){原创 2017-03-06 11:32:58 · 303 阅读 · 0 评论 -
PAT-A1012
#include#include#includeusing namespace std;struct people{ char id[8]; int c, cr; int m, mr; int e, er; int a, ar;}peo[2010];bool cmpa(people k, people b){ return k.a>b.a; //else return s原创 2017-03-06 11:32:29 · 178 阅读 · 0 评论 -
PAT-A1011
#includeint main(){int i, n, maxi=0 ;char out[3];double a, b, c, max=1.0 ;for(i=0;i<3;i++){ scanf("%lf%lf%lf",&a,&b,&c); if(a>b){ if(a>c){out[i]='W';max*=a;} else {out[i]='L';max*=c;} }原创 2017-03-06 11:31:45 · 221 阅读 · 0 评论 -
PAT-A1009
#include #includeint main(){ int n, i, j, temp1, count = 0; double temp2,a[1002], sum[2002]={0}; memset(a,0,sizeof(a)); scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d",&temp1); scanf("%lf",&a原创 2017-03-06 11:27:07 · 215 阅读 · 0 评论 -
PAT-A1008
#includeint main(){int i, n, now=0, temp, ans=0;scanf("%d",&n);for(i=0;i<n;i++){ scanf("%d",&temp); if(temp>now){ans+=(temp-now)*6;ans+=5;} else {ans+=(now-temp)*4;ans+=5;} now=temp;}printf(原创 2017-03-06 11:26:28 · 247 阅读 · 0 评论 -
PAT-A1001
#includeint main(){ int a,b; while(scanf("%d%d",&a,&b)!=EOF){ int c = a+b; if(c<0){ c=-c; printf("-"); } if(c>=1000000) pri原创 2017-03-06 11:08:10 · 224 阅读 · 0 评论 -
PAT-A1002
#include #includeint main(){ int n,i,temp; double a[1002],b[1002]; memset(a,0,sizeof(a)), memset(b,0,sizeof(b)); //输入 scanf("%d",&n); for(i=0;i scanf("%d",&原创 2017-03-06 11:10:18 · 252 阅读 · 0 评论 -
PAT-A1005
#includeint main(){ char c,dig[100]; int i=0; int sum=0; for(i=0;i<100;i++){ //输入 dig[i]=getchar(); } for(i=0;i<100;i++){ //计算sum sum+=dig[i]; }return 0;}原创 2017-03-06 11:16:57 · 225 阅读 · 0 评论 -
PAT-A1004
#include#includeusing namespace std;int n, m, max_depth=-1;struct pnode{ vector child;}node[110];int level_num[110]={0};void DFS(int root, int depth){ if(node[root].child.size()==0){level_num原创 2017-03-06 11:23:27 · 272 阅读 · 0 评论 -
PAT-A1006
#includeint main(){int i, n, h1, h2, m1, m2, s1, s2, temp1=100,temp2=100, temp3=100, k1=0;int temp4=0, temp5=0, temp6=0, k2=0;char a[1000][17];scanf("%d",&n);for(i=0;i<n;i++){scanf("%s%d:%d:%d原创 2017-03-06 11:24:58 · 461 阅读 · 0 评论 -
PAT-A1021
#include#include#include#includeusing namespace std;int n, father[10010]={0}, isfather[10010]={0};vector G[10010];int findfa(int x){ int temp, xx=x; while(father[x]!=x){ x=father[x]; } wh原创 2017-03-06 11:51:27 · 297 阅读 · 0 评论