Zhejiang University PAT exam 1077 ~ 1080 (2014 superior review questions), 10772014

Source: Internet
Author: User

Zhejiang University PAT exam 1077 ~ 1080 (2014 superior review questions), 10772014

Address: http://pat.zju.edu.cn/contests/pat-a-practise


It is still too weak ..


English is too bad ,,,


It is estimated that it will wait for abuse ..


1077

Find the longest public suffix and write it as follows:

#include<iostream>#include<cstdio>#include<cmath>#include<algorithm>#include<cstring>#include<string>using namespace std;char  a[105][1005];int milen;void myreverse(char *s){    int len=strlen(s);    milen=min(len,milen);    for(int i=0; i<len/2; i++)    {        char tmp=s[i];        s[i]=s[len-1-i];        s[len-1-i]=tmp;    }}int main(){    int n,i,j;    while(cin>>n)    {        gets(a[0]);        milen=10005;        for(i=0; i<n; i++)        {            gets(a[i]);            myreverse(a[i]);        }        for(i=0; i<milen; i++)        {            int flag=0;            for(j=1; j<n; j++)            {                if(a[j][i]!=a[0][i])                {                    flag=1;                    break;                }            }            if(flag) break;        }        int p=i;        char ans[1005];        for(i=0; i<p; i++)            ans[i]=a[0][i];        ans[i]='\0';        myreverse(ans);        if(p==0) puts("nai");        else printf("%s\n",ans);    }    return 0;}/*3Itai nyan~Ninjin wa iyadanyan~uhhh nyan~3Itai!Ninjinnwaiyada T_TT_T*/


1078:

Hash, secondary detection, and unreadable words ..

# Include <cstdio> # include <cmath> # include <iostream> # include <cstring> # include <string> using namespace std; const int maxn = 20005; int prim [maxn]; int mp [maxn]; int tmpprim [maxn]; int visi [maxn]; int ans [maxn]; void sxprim () {int I, j; memset (prim, 1, sizeof (prim); prim [1] = 0; for (I = 2; I <maxn; I ++) {if (prim [I]) {for (j = I * 2; j <maxn; j + = I) prim [j] = 0 ;}} int cnt = 0; for (I = maxn-1; I> = 2; I --) {if (prim [I]) tmpprim [cnt ++] = I;} For (I = 0; I <cnt-1; I ++) {int tmp = tmpprim [I]; int k = tmpprim [I + 1]; for (j = tmp; j> k; j --) mp [j] = tmp;} for (j = 1; j <= tmpprim [cnt-1]; j ++) mp [j] = tmpprim [cnt-1]; // for (I = 1; I <= 20; I ++) // cout <I <"" <mp [I] <endl;} int main () {sxprim (); int mod, n, I; while (cin> mod> n) {mod = mp [mod]; // re-defined memset (visi, 0, sizeof (visi )); for (I = 0; I <n; I ++) {int x; cin> x; int cur = x % mod; if (! Visi [cur]) {visi [cur] = 1; ans [I] = cur;} else {int cnt = 1; int flag = 0; while (cnt <= maxn) // The detection method is incorrect .. {Int p = (cnt * cnt + cur) % mod; if (! Visi [p]) {visi [p] = 1; ans [I] = p; flag = 1; break;} cnt ++;} if (! Flag) ans [I] =-1 ;}for (I = 0; I <n; I ++) {if (I) cout <""; if (ans [I]> = 0) cout <ans [I]; else cout <"-" ;}cout <endl ;}return 0 ;} /* 11 82 2 2 2 2 2 2 */


1079:

It is to give you a tree, find the leaf node, the leaf node has a value, and then from the root down each layer will increase with r %.

No preprocessing will time out ..

# Include <iostream> # include <cstdio> # include <cmath> # include <cstring> # include <string> # include <algorithm> # include <vector> const int maxn = 100005; using namespace std; vector <int> mq [maxn]; int n; double p, r;/* double cal (int step) {double ans = p; for (int I = 0; I <step; I ++) ans = ans * (r/100.0 + 1.0); return ans;} */double tt [maxn]; void cal () // It will not time out after preprocessing, and the time is changed to {tt [0] = p; for (int I = 1; I <maxn; I ++) tt [I] = tt [I-1] * (1.0 + r/100.0);} int height [maxn]; double val [maxn]; double ans; void dfs (int cur) {int len = mq [cur]. size (); int I; if (len = 0) {ans + = val [cur] * tt [height [cur]; return ;} else {for (I = 0; I <len; I ++) {int p = mq [cur] [I]; height [p] = height [cur] + 1; dfs (p) ;}}int main () {int I; while (cin >>> n) {cin >>> p >> r; cal (); for (I = 0; I <n; I ++) mq [I]. clear (); height [0] = 0; int x, chi; for (I = 0; I <n; I ++) {cin> x; if (x) {while (x --) {cin> chi; mq [I]. push_back (chi) ;}} else {cin> val [I] ;}}ans = 0; dfs (0); printf ("%. 1f \ n ", ans);} return 0;}/* 10 1.80 1.003 2 3 51 91 41 70 72 6 11 80 90 40 3 */


1080:

In the end, only 24/30 points can be obtained. There is an error and a data segment is incorrect.

I guess the data is that each school has a quota of 0 .. Otherwise, it would be unreasonable ..

# Include <iostream> # include <cstdio> # include <cmath> # include <cstring> # include <string> # include <algorithm> # include <vector> # include <set> const int maxn = 40005; using namespace std; int n, m, k; int peo [maxn]; // set <int> ans [maxn]; // set <int>: iterator mq; vector <int> ans [105]; struct node {int index; int ge; int gi; int total; int aim [6];} nod [maxn]; struct nodd {int ge; int gi;} last [105]; // Save the person with the lowest admission score for each school. Int cmp (node p1, node p2) {if (p1.total> p2.total) return 1; else if (p1.total = p2.total & p1.ge> p2.ge) return 1; // else if (p1.total = p2.total & p1.ge = p2.ge & p1.gi> p2.gi) return 1; return 0 ;}int main () {int I, j; int a [10]; while (cin> n> m> k) {for (I = 0; I <n; I ++) ans [I]. clear (); for (I = 0; I <m; I ++) cin> peo [I]; for (I = 0; I <n; I ++) {cin> nod [I]. ge> nod [I]. gi; for (j = 0; j <k; j ++) cin> nod [I]. aim [j]; nod [I]. t Otal = nod [I]. ge + nod [I]. gi; nod [I]. index = I;} sort (nod, nod + n, cmp); for (I = 0; I <n; I ++) {for (j = 0; j <m; j ++) a [j] = nod [I]. aim [j]; for (j = 0; j <m; j ++) {if (peo [a [j]) {peo [a [j] --; ans [a [j]. push_back (nod [I]. index); if (peo [a [j] = 0) {last [a [j]. ge = nod [I]. ge; last [a [j]. gi = nod [I]. gi;} break;} else {if (nod [I]. ge = last [a [j]. ge & nod [I]. gi = last [a [j]. gi) {ans [a [j]. push_back (nod [I]. index); break ;}}} fo R (I = 0; I <m; I ++) {if (ans [I]. size () = 0) puts (""); else {int len = ans [I]. size (); sort (ans [I]. begin (), ans [I]. end ();/* mq = ans [I]. begin (); int flag = 0; for (; mq! = Ans [I]. end (); mq ++) {if (flag) cout <"; else flag = 1; cout <* mq;} */for (j = 0; j <len; j ++) {if (j> 0) cout <""; cout <ans [I] [j];} cout <endl ;}} return 0 ;} /* 11 6 32 1 2 2 3100 100 0 1 260 60 2 3 5100 90 0 3 490 100 1 2 090 90 5 1 380 90 1 0 280 80 0 1 280 80 0 1 280 70 1 3 270 80 1 2 3100 100 0 2 4 */




Only C/C ++ can be used for the PAT test of Zhejiang University? Can I use JAVA?

I have participated in this article. I can submit it in Java, but the server will translate Java into C language, but the correctness is not guaranteed. You can go to the Question Bank to try it. For example, there is a taxi pricing in the exercise questions, java cannot write the fourth use case. C can.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.