PTA练习题
PTA的一些实例,相互交流
hj_cheng29
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
实验7-1-10 交换最小值和最大值 (15分)
本以为两分钟就写得出来,没想到还是花了我5分钟QAQ有提示就是好,要是复试上机每个测试点也有提示就好了!#include <stdio.h>int main(){ int n,i,max=0,min=0,maxnum=-12220,minnum=12220; scanf("%d",&n); int a[n]; for(i=0;i<n;i++){ scanf("%d",&a[i]); if(maxnum.原创 2020-05-14 15:09:31 · 2561 阅读 · 0 评论 -
7-2 然后是几点 (15分)
要设置很多变量就是取名字有点麻烦,题不是难题,各种if else就可以做,逻辑清晰的话很快就能AC#include <stdio.h>int main(){ int originTime,addTime,curTime; scanf("%d %d",&originTime,&addTime); int addh = addTime/60; int addf = addTime%60; int i=0; int orih = originTime/1.原创 2020-05-11 09:09:57 · 324 阅读 · 1 评论 -
(考前复习)7-1 厘米换算英尺英寸 (15分)
/*这道题给的公式真的看晕了,实际上,foot就是整数部分,inch就是小数部分然后*12 前面一直理解成换算成 米/0.3048后 要/12为foot,剩下的余数为inch , 根本理解错误了 都怪这个公式给的 _(¦3」∠)_*/#include <stdio.h>int main(){ int lon,foot,inch; double mi; scanf("%d",&lon); mi = lon*1.0/100;//换算成米的单位 mi = m.原创 2020-05-10 11:18:53 · 985 阅读 · 1 评论 -
7-21 求特殊方程的正整数解 (15分)
#include <stdio.h>#include <math.h>int main(){ int n,x,y,flag=0; scanf("%d",&n); for(x=1;x<sqrt(n/2);x++){ //这里要小于sqrt(n/2)是因为答案会多一倍,后半部分的答案就是前半部分的x,y颠倒,毕竟这个方程x和y是等价的! int temp = n-x*x; y = (int)sqrt(temp); if(sqrt(.原创 2020-05-10 10:25:53 · 339 阅读 · 0 评论 -
(考前复习!)7-15 计算圆周率 (15分)
最开始的代码,但是一直都错#include <stdio.h>double getJc(double a);int getFm(int a);int main(){ double threshold; scanf("%lf",&threshold); double pi=0; double i=0; double a = getJc(i)*1.0...原创 2020-05-08 10:54:10 · 254 阅读 · 0 评论 -
(qsort方法排序flaot类型的数)6-11 求自定类型元素序列的中位数 (25分)
#include<stdlib.h>int cmp(void const *a,void const *b){ return (*(ElementType*)b)>(*(ElementType*)a) ? 1:-1; //因为题中说的是第(N+1)/2大的,所以要逆序。}ElementType Median( ElementType A[], int N ){...原创 2020-04-29 10:42:38 · 145 阅读 · 0 评论 -
6-10 阶乘计算升级版 (20分)
由于N很大了过后,就超过了int的范围了,故我们只能用数组模拟乘法AC代码void Print_Factorial ( const int N ){ if(N<0){ printf("Invalid input"); return; } int num[1000000] = {0}; int i,j,k=0,temp,y=0;//y是余数,k代...原创 2020-04-28 15:45:27 · 194 阅读 · 0 评论 -
自测-5 Shuffling Machine (20分)
#include <stdio.h>#include <stdlib.h>#include <string.h>char cards[55][4] = {"S1","S2","S3","S4","S5","S6","S7","S8","S9","S10","S11","S12","S13","H1","H2","H3","H4","H5","H6",...原创 2020-04-21 11:05:58 · 118 阅读 · 0 评论 -
自测-4 Have Fun with Numbers (20分)
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number con...原创 2020-04-20 17:25:06 · 354 阅读 · 0 评论 -
自测-2 素数对猜想 (20分)
#include <stdio.h>#include <math.h>int PutIndexToPrim(int index);int main(){ int n,num,i=1,count=0,d; scanf("%d",&num); while(PutIndexToPrim(i+1)<=num){ d =...原创 2020-04-20 16:24:39 · 165 阅读 · 0 评论 -
自测-1 打印沙漏 (20分)
只要细心一步步来就可以做出来#include <stdio.h>#include <stdlib.h>int GetL(int num);int main(){ int num,i,j; char ch; scanf("%d %c",&num,&ch); int l = GetL(num); //上半部分有多高,包...原创 2020-04-20 15:47:00 · 153 阅读 · 0 评论 -
(考前复习)基础实验3-2.2 单链表分段逆转 (25分)
单链表逆序不一定要用头插法从新建一个链表,可以节点间的交换/*思路:*/void K_Reverse( List L, int K ){ List H = (List)malloc(sizeof(struct Node)); H->Next = NULL; int i = 0,len=0,cnt; List p = L->Next,q = L,...原创 2020-04-20 10:19:24 · 1058 阅读 · 0 评论 -
进阶实验2-3.3 两个有序链表序列的交集 (20分)
#include <stdio.h>#include <stdlib.h>typedef struct node{ int data; struct node *next;}*LinkList;LinkList createList();void FindMixed(LinkList L1,LinkList L2);int main(){...原创 2020-04-17 11:01:41 · 780 阅读 · 0 评论 -
L1-054 福到了 (15分) C语言
#include <stdio.h>int main(){ char flag,ch; int i,n,j,count=0; scanf("%c%d",&flag,&n); getchar(); //接收缓冲区中的回车 char arr[n+1][n+1]; for(i=0;i<n;i++){ ...原创 2020-04-10 11:12:01 · 2735 阅读 · 0 评论 -
L1-033 出生年 (15分) C语言
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>int Jugement(int year,int num);int main(){ int year,num,count=0; scanf("%d %d",&yea...原创 2020-04-08 11:08:32 · 1423 阅读 · 1 评论 -
L1-025 正整数A+B (15分) C语言
认真读题:B中可能包含空格所以B不能用scanf来读取!!!#include <stdio.h>#include <stdlib.h>#include <string.h>int IsStanderd( char *A);int main(){ char A[20]; char B[20]; scanf("%s",A);...原创 2020-04-06 10:10:29 · 1226 阅读 · 1 评论 -
L1-023 输出GPLT (20分)
认真读题,调整顺序后输出#include <stdio.h>#include <string.h>int main(){ char a[10001]; gets(a); int i; int g=0,p=0,l=0,t=0; for(i=0;i<strlen(a);i++){ if(a[i]=='G'|...原创 2020-04-05 10:44:12 · 239 阅读 · 0 评论 -
L1-011 A-B (20分)
解决方案:先对B的所有字符进行标记,然后遍历A未标记过的直接输出#include <stdio.h>#include <stdlib.h>int main(){ char s1[10010]; char s2[10010]; gets(s1); gets(s2); int a[256]; memset(a,0,siz...原创 2020-04-04 10:23:29 · 561 阅读 · 1 评论 -
7-29 删除字符串中的子串 (20分)
#include <stdio.h>#include <stdlib.h>int main(){ char s1[81]; char s2[81]; gets(s1); gets(s2); int L1 = strlen(s1); int L2 = strlen(s2); int i,j=0,flag=0; ...原创 2020-04-01 16:23:29 · 505 阅读 · 0 评论 -
7-37 整数分解为若干项之和 (20分)dfs算法复习
有点疑惑这道题为啥通过率这么高!!!这道题要用dfs算法来实现#include <stdio.h>#include <stdlib.h>int s[31];int sum = 0;int count = 0;int top = -1;void dfs(int n,int i){ if(sum==n){ count++; ...原创 2020-04-01 15:39:50 · 346 阅读 · 1 评论 -
7-32 说反话-加强版 (20分)
本题可以很简单的做出来,就是逆序遍历,然后发现单词就入栈,直到单词头部就出栈,先进后出,代码也很简单。#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){ char a[500001]; char stack[500001]; gets(a);...原创 2020-04-01 10:06:52 · 398 阅读 · 1 评论 -
7-28 猴子选大王 (20分)
#include <stdio.h>#include <stdlib.h>int main(){ int n,i=0,k=0,j,t=1; scanf("%d",&n); int out[n]; for(j=1;j<=n;j++){ out[j] = 0; } while(k<n-1...原创 2020-03-31 16:14:29 · 262 阅读 · 0 评论
分享