PAT甲级
dayL_W
热爱编程、热爱生活、热爱运动
展开
-
1049. Counting Ones (30)
题目:https://www.patest.cn/contests/pat-a-practise/1049#includeint main(){ int n,a=1,left,now,right,ans=0; scanf("%d",&n); while(n/a) { left = n/(a*10); now = n/a % 10; right =原创 2017-04-15 14:21:13 · 170 阅读 · 0 评论 -
1075. PAT Judge (25)
//分数相同按解决问题的数量#include#include#includeusing namespace std;struct pat{ int problems[6]; int problems_flag; int score; int sloved; int id; int rank;}stu[10010];bool cmp(pat原创 2017-05-10 19:57:34 · 165 阅读 · 0 评论 -
1074. Reversing Linked List (25)
//用order记录节点的序号!!!#include#includeusing namespace std;#define maxn 100010struct Node{ int address,data,next; int order; Node() { address = 0; data = 0; next = -1; order原创 2017-05-10 19:56:32 · 168 阅读 · 0 评论 -
1072. Gas Station (30)
#include#include#includeusing namespace std;#define maxn 1020#define INF 1000000000int n,m,k,ds,n_all=0;int G[maxn][maxn],vis[maxn]={false},d[maxn];int all_dis=0,min_dis=INF,flag=0,all_flag=0原创 2017-05-10 19:54:24 · 169 阅读 · 0 评论 -
1071. Speech Patterns (25)
//1071. Speech Patterns (25)#include#include#include#includeusing namespace std;int flag[256]={0};void init(){ for(int i='0'; i<='9'; i++) flag[i] = 1; for(int i='a'; i<='z'; i++)原创 2017-05-10 19:53:07 · 151 阅读 · 0 评论 -
1069. The Black Hole of Numbers (20)
#include#includeusing namespace std;int a[4];int x;void to_arry(int num){ for(int i=0; i<4; i++) { a[i] = num%10; num = num/10; } }int to_num(int a[],int x){ int temp=0原创 2017-05-10 19:52:29 · 217 阅读 · 0 评论 -
1067. Sort with Swap(0,*) (25)
#include#includeusing namespace std;const int maxn = 100010;int pos[maxn];int main(){ int n,ans=0; scanf("%d",&n); int left = n-1,num; for(int i=0; i<n; i++) { scanf("%d",&num);原创 2017-05-10 19:51:32 · 140 阅读 · 0 评论 -
1066. Root of AVL Tree (25)
#include#includeusing namespace std;#define maxn 30struct node{ int v,heigth; node *lchild,*rchild;};int data[maxn]={0},n;node* newN(int x){ node* now = new node; now->v = x; now-原创 2017-05-10 19:50:05 · 171 阅读 · 0 评论 -
1064. Complete Binary Search Tree (30)
#include#include#define maxn 1010using namespace std;struct node{ int data;}tree[maxn];int head = 1,cnt=0,N,input[maxn]={0};int output[maxn]={0};void in_order(int head){ //判空是head>N原创 2017-05-10 19:49:01 · 191 阅读 · 0 评论 -
1063. Set Similarity (25)
#include#includeusing namespace std;int main(){ set num[60]; set sum; int N=0,M=0,K=0,temp,set1,set2,NC=0,NT=0; scanf("%d",&N); for(int i=1; i<=N; i++) { scanf("%d",&M); for(i原创 2017-05-10 19:47:56 · 198 阅读 · 0 评论 -
1061. Dating (20)
#include#include#define maxn 65char str1[65],str2[65],str3[65],str4[65];char ch[8][5]={" ","MON","TUE","WED","THU","FRI","SAT","SUN"};int d,h,m;int flag=0;int main(){ scanf("%s%s%s%s",str1,原创 2017-05-10 19:47:01 · 157 阅读 · 0 评论 -
1060. Are They Equal (25)
#include#include#includeusing namespace std;int N;string deal(string s1,int &e1){ int k=0; while(s1[0]=='0' && s1.length()>0) { s1.erase(s1.begin()); } if(s1[0]=='.') { s1.e原创 2017-05-10 19:44:56 · 158 阅读 · 0 评论 -
1059. Prime Factors (25)
#include#includeusing namespace std;#define maxn 100010int prime[maxn]={0};bool p[maxn]={0};struct factor{ int x; int cnt;}fac[10];void init_p(){ int x=0; p[0] = p[1] = true; for原创 2017-05-10 19:44:10 · 143 阅读 · 0 评论 -
1058. A+B in Hogwarts (20)
#includeint main(){ int a1=0,b1=0,c1=0,a2=0,b2=0,c2=0; int x1,y1,z1; int carry=0; scanf("%d.%d.%d",&a1,&b1,&c1); scanf("%d.%d.%d",&a2,&b2,&c2); x1 = (c1+c2)%29; carry = (c1+c2)/29;原创 2017-05-10 19:42:57 · 194 阅读 · 0 评论 -
1055. The World's Richest (25)
//1055. The World's Richest (25)#include#include#includeusing namespace std;struct people{ char name[10]; int age; int worth;}People[100000];bool cmp(people a, people b){ if(a.wort原创 2017-05-10 19:41:35 · 189 阅读 · 0 评论 -
1054. The Dominant Color (20)
#include#include#include#includeusing namespace std;int main(){ map mp; int M,N; int color,MAX=0,k=0; scanf("%d%d",&M,&N); for(int i=0; i<N; i++) { for(int j=0; j<M; j++) {原创 2017-05-10 19:41:00 · 172 阅读 · 0 评论 -
1053. Path of Equal Weight (30)
#include#include#include#define maxn 110using namespace std;struct node{ int weight; vector child;}tree[maxn];int N,M,K,S,id;int path[maxn]={0};bool cmp(int a, int b){ return tree[a原创 2017-05-10 19:39:21 · 143 阅读 · 0 评论 -
1050. String Subtraction (20)
题目:https://www.patest.cn/contests/pat-a-practise/1050#include#includeint main(){ char str1[10010]; char str2[10010]; int len1=0,len2=0,flag[256]={0},i=0,j=0; gets(str1); gets(str2);原创 2017-05-10 19:35:16 · 142 阅读 · 0 评论 -
1085. Perfect Sequence (25)
//方法2#include#includeusing namespace std;int maxn[100010];int main(){ int n=0,p=0; scanf("%d%d",&n,&p); int i=0; for(i=0; i<n; i++) scanf("%d",&maxn[i]); sort(maxn, maxn+n); int原创 2017-05-10 20:12:23 · 237 阅读 · 0 评论 -
1084. Broken Keyboard (20)
#include#includeint main(){ char str1[100]; char str2[100]; int i=0,j=0,flag[128]={0}; scanf("%s%s",str1,str2); int len1 = strlen(str1); int len2 = strlen(str2); for(i=0,j=0; i<len1原创 2017-05-10 20:10:37 · 330 阅读 · 0 评论 -
1083. List Grades (25)
#include#include#includeusing namespace std;struct stu{ char name[13]; char id[13]; int grade;}Stu[100];bool cmp(stu a, stu b){ return a.grade>b.grade;}int main(){ int N=0,M=0;转载 2017-05-10 20:09:49 · 248 阅读 · 0 评论 -
1076. Forwards on Weibo (30)
#include#include#includeusing namespace std;#define maxn 1010struct Node{ int id; int layer;};vector G[maxn];bool vis[maxn]={false};int n,L,x,k,i,j,cnt=0;Node node,temp;//广度遍历,u为当前遍历的原创 2017-05-13 19:44:06 · 280 阅读 · 0 评论 -
1076. Forwards on Weibo (30)
#include#include#includeusing namespace std;#define maxn 1010struct Node{ int id; int layer;};vector G[maxn];bool vis[maxn]={false};int n,L,x,k,i,j,cnt=0;Node node,temp;//广度遍历,u为当前遍历的原创 2017-05-10 20:08:11 · 226 阅读 · 0 评论 -
1080. Graduate Admission (30)
#include#include#include#includeusing namespace std;struct stu{ int GE; int GI; int score; int ranks; int id; int choices[6];}App[40010];struct school{ int quota; int stuNum原创 2017-05-10 20:05:53 · 229 阅读 · 0 评论 -
1079. Total Sales of Supply Chain (25)
//1079. Total Sales of Supply Chain (25)#include#includeusing namespace std;#define maxn 100010struct node{ double price; int sale; vector child;}tree[maxn];int head=0,N;double init_p原创 2017-05-10 20:04:20 · 145 阅读 · 0 评论 -
1100. Mars Numbers (20)
#include#include#include#includeusing namespace std;string low[13] = {"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};string high[13] = {"tret","tam",原创 2017-05-13 19:41:06 · 167 阅读 · 0 评论 -
1099. Build A Binary Search Tree (30)
#include#include#includeusing namespace std;#define maxn 200struct node{ int data; int rchild,lchild;}tree[maxn];int head=0,N,in[maxn]={0},cnt=0,flag=0;void in_order(int root){ if(原创 2017-05-13 19:39:40 · 127 阅读 · 0 评论 -
1098. Insertion or Heap Sort (25)
//1098. Insertion or Heap Sort (25)#include#includeusing namespace std;#define maxn 150int origin[maxn],back[maxn],changed[maxn];int n;bool issame(int a[]){ for(int i=1; i<=n; i++) {原创 2017-05-13 19:39:00 · 149 阅读 · 0 评论 -
1097. Deduplication on a Linked List (25)
#include#includeusing namespace std;#define maxn 100010struct Node{ int address,data,next; int order; Node() { next = -1; order = 2*maxn; }}node[maxn];bool cmp(Node a, Node原创 2017-05-13 19:38:20 · 217 阅读 · 0 评论 -
1096. Consecutive Factors (20)
#include#includeint main(){ long long len=0,best_len=0,ans = 0,best_ans=0,x=2,temp=0,y=2; long long num=0,back=0; scanf("%lld",&back); num = back; temp = (long long)sqrt(1.0*num)原创 2017-05-13 19:37:38 · 268 阅读 · 0 评论 -
1094. The Largest Generation (25)
#include#include#includeusing namespace std;#define maxn 200struct node{ int data; int level; vector child;}tree[maxn];int head = 1,N,K,max_level=1,max_cnt=0;int father,n;int has[max原创 2017-05-13 19:36:36 · 154 阅读 · 0 评论 -
1092. To Buy or Not to Buy (20)
#include#includeint main(){ char str1[1010],str2[1010]; int flag[256]={0},len1,len2,i; int more=0,less=0,temp=0; scanf("%s%s",str1,str2); len1 = strlen(str1); len2 = strlen(str2); for原创 2017-05-13 19:35:40 · 149 阅读 · 0 评论 -
1090. Highest Price in Supply Chain (25)
#include#include#includeusing namespace std;#define maxn 100010struct node{ double price; vector child;}tree[maxn];int N,head,cnt=0;double init_price,r,max_price=0;void level_order(in原创 2017-05-13 19:34:35 · 151 阅读 · 0 评论 -
1088. Rational Arithmetic (20)
#include#includeusing namespace std;struct Fraction{ long long up,down;};long long gcd(long long a,long long b){ if(b == 0) return a; else return gcd(b,a%b);}Fraction reduction(Fracti原创 2017-05-13 19:33:44 · 151 阅读 · 0 评论 -
1087. All Roads Lead to Rome (30)
//dijstra#include#include#include#include#include#includeusing namespace std;#define maxn 1000#define INF 1000000000map cityToNum;map NumTocity;int n,m,G[maxn][maxn];int vis[maxn]={fal原创 2017-05-13 19:32:37 · 307 阅读 · 0 评论 -
1086. Tree Traversals Again (25)
//1086. Tree Traversals Again (25)#include#include#includeusing namespace std;struct node{ int data; node *lchild,*rchild;}*head;int pre[40]={0}, in[40]={0},N=0,flag=0;node* creat(int p原创 2017-05-13 19:31:24 · 223 阅读 · 0 评论 -
1081. Rational Sum (20)
#include#includestruct Fraction{ int up,down;};int gcd(int a,int b){ if(b == 0) return a; else return gcd(b,a%b);}Fraction reduction(Fraction f1){ if(f1.down<0) { f1.up = -f1.原创 2017-05-10 20:07:14 · 177 阅读 · 0 评论 -
1078. Hashing (25)
#include#includeusing namespace std;#define maxn 100010bool p[maxn]={false};void init_p(){ p[0] = p[1] = true; for(int i=2; i<maxn; i++) { if(p[i] == false) { for(int j=i*2原创 2017-05-10 20:02:43 · 141 阅读 · 0 评论 -
1051. Pop Sequence (25)
题目:https://www.patest.cn/contests/pat-a-practise/1051#include#includeusing namespace std;int main(){ int M,N,K,flag = 1,x=0,temp; int Arry[1000]={0}; stack st; scanf("%d%d%d",&M,&N,&K)原创 2017-05-10 19:36:03 · 156 阅读 · 0 评论 -
1052. Linked List Sorting (25)
题目:https://www.patest.cn/contests/pat-a-practise/1052#include#includeusing namespace std;#define maxn 100010struct Node{ int address,next; int data; int flag; Node() { address = 0原创 2017-05-10 19:37:37 · 169 阅读 · 0 评论