- 博客(27)
- 收藏
- 关注
原创 P1067 多项式输出
P1067 多项式输出 - 洛谷 | 计算机科学教育新生态 https://www.luogu.org/problem/P1067 #include<iostream> using namespace std; int N,i,a,b; int main() { cin>>N; for(i=N;i>=0;i--) { cin>>a; i...
2019-10-18 21:24:35
188
原创 P1003 铺地毯
P1003 铺地毯 - 洛谷 | 计算机科学教育新生态 https://www.luogu.org/problem/P1003 代码1. #include<iostream> #include<vector> #define MAX 20010 using namespace std; int N,i,a,b,c,d,j,k,x,y; int s[MAX][MAX...
2019-10-18 21:23:41
175
原创 P1449 后缀表达式
代码1.利用栈原理 P1449 后缀表达式 - 洛谷 | 计算机科学教育新生态 https://www.luogu.org/problem/P1449 #include<iostream> #include<stack> using namespace std; int main() { char c; stack<int>s; int ans=0;...
2019-10-17 22:04:55
217
原创 P1739 表达式括号匹配
P1739 表达式括号匹配 - 洛谷 | 计算机科学教育新生态 https://www.luogu.org/problem/P1739 * *代码1. ** 普通思想 #include<iostream> using namespace std; int main() { int num=0; char c; while(cin>>c) { if(...
2019-10-16 23:10:10
166
原创 P1115 最大子段和
P1115 最大子段和 - 洛谷 | 计算机科学教育新生态 https://www.luogu.org/problem/P1115 #include<iostream> #include<algorithm>//加上这个头文件可以在下面直接使用max 求最大值函数 #define MAX 5010 #define INF 0x3f3f3f using namespace ...
2019-10-16 17:50:47
121
原创 P1739 表达式括号匹配
假设一个表达式有英文字母(小写)、运算符(+,—,*,/)和左右小(圆)括号构成,以“@”作为表达式的结束符。请编写一个程序检查表达式中的左右圆括号是否匹配,若匹配,则返回“YES”;否则返回“NO”。表达式长度小于255,左圆括号少于20个。
2019-10-12 20:47:43
165
原创 P1996 约瑟夫问题
n个人(n<=100)围成一圈,从第一个人开始报数,数到m的人出列,再由下一个人重新从1开始报数,数到m的人再出圈,……依次类推,直到所有的人都出圈,请输出依次出圈人的编号.
2019-10-12 20:18:22
124
原创 【C语言训练】"水仙花数"问题2
输出所有的"水仙花数".所谓"水仙花数"是指这样的一个三位数:其各位数字的立方和等于该数本身。例如:371是一个"水仙花数",371=3^3+7^3+1^3.
2019-05-24 17:05:26
501
原创 [编程入门]筛选N以内的素数
#include<stdio.h> int main() { int N; int i; int a =0; int num=0; int k=0; scanf("%d",&N); for(i=2;i<=N;i++) { for(a=2;a<=i;a++) { k=i%a; if(k0) break; } if(ai) { printf("%d\n",i); } }...
2019-05-24 16:38:48
337
原创 数字的处理与判断
#include<stdio.h> int main() { int num[5]; int n; //输入的数字 int number=0;//记录数字的位数 int i; scanf("%d",&n); for(i=0;i<5;i++) { if(n==0)break; else { num[i]=n%10 ;//num[0]为最后一位数字 循环出每个数字 1%10=...
2019-05-24 00:22:47
318
原创 跳一跳
#include<stdio.h> int main() { int a=0,sum=0,plus=0; while(scanf("%d",&a)!=EOF&&a) { if(a==1) { sum+=a; plus=0; } if(a==2) { sum+=a; sum+=plus; plus+=2; ...
2019-05-23 13:16:00
950
原创 [编程入门]密码破译
要将"China"译成密码,译码规律是:用原来字母后面的第4个字母代替原来的字母. 例如,字母"A"后面第4个字母是"E"."E"代替"A"。因此,"China"应译为"Glmre"。 请编一程序,用赋初值的方法使cl、c2、c3、c4、c5五个变量的值分别为,’C’、’h’、’i’、’n’、’a’,经过运算,使c1、c2、c3、c4、c5分别变为’G’、’l’、’m’、’r’、’e’,并输出。
2019-05-22 00:01:43
1730
2
原创 【C语言训练】求s=a+aa+aaa+aaaa+aa...a的值
求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个一位的整数。 例如2+22+222+2222+22222(此时共有5个数相加)
2019-05-17 21:17:21
15939
原创 陶陶摘苹果
陶陶家的院子里有一棵苹果树,每到秋天树上就会结出10个苹果。苹果成熟的时候,陶陶就会跑去摘苹果。陶陶有个30厘米高的板凳,当她不能直接用手摘到苹果的时候,就会踩到板凳上再试试。 现在已知10个苹果到地面 ...输入包括两行数据。第一行包含10个100到200之间(包括100和200)的整数(以厘米为单位)分别表示10个苹果到地面的高度,两个相邻的整数之间用一个空格隔开。第二行只包括一个100到120之间(包含100和120)的整数(以厘米为单位),表示陶陶把手伸直的时候能够达到的最大高度。
2019-05-17 21:09:08
248
原创 [编程入门] C语言 最大公约数与最小公倍数
#include<stdio.h> int main(){ int a,b,num1,num2,temp; scanf("%d%d",&num1,&num2); if(num1<num2){ temp = num1; num1 = num2; num2 = temp; } a = num1; b = num2; while(b!=0){ /利用辗除法,直到b为...
2019-05-17 17:52:56
1344
原创 定义一个符号常量,记录一年中总小时数,用户输入一年中任意一个小时,则输出已过去多少年
#include<stdio.h> #define Hour_years (365*24) int main() { float h; printf(“请输入一个小时数”); scanf("%f",&h); printf("%3fyear(s)",h/Hour_years ); return 0; }
2019-04-15 18:01:13
993
原创 用fputc将字符写进指定的文件中(字符用for循环来写)
#include&lt;stdio.h&gt; int main() { FILE*fp; int i; char chs[10]={‘L’,‘O’,‘V’,‘E’}; fp=fopen(“hello.txt”,“wt”); if(fp!=NULL) { for(i=0;i&lt;5;i++) { fputc(chs[i],fp); } } return 0; } ...
2019-03-17 11:41:05
323
原创 用fputc把字符写入指定的文件中
#include<stdio.h> int main() { FILE*fp; char chs[10]={‘L’,‘O’,‘V’,‘E’}; fp=fopen(“hello.txt”,“wt”); if(fp!=NULL) { fputc(chs[0],fp); fputc(chs[1],fp); fputc(chs[2],fp); fputc(chs[3],fp); } retur...
2019-03-17 11:32:26
716
原创 fgets字符串形式读取文件(待定)
#include<stdio.h> void main() { FILE*fp;//文件指针 char ch[200]; char *c; fp=fopen(“hello.txt”,“rt”); if(fpNULL) { puts(“文件不存在”); } else { while(1) { c=fgets(ch,50,fp); if(cNULL) { break; } puts(ch)...
2019-03-17 11:21:18
295
原创 输入三个字符串, 按有小到大排序*( 指针)
#include #include using namespace std; int main() { void swap(char*,char*);//函数声明 char str1[20],char str2[20],char str3[30]; cout&lt;&lt;“请输入三个字符串:”&lt;&lt;endl; gets( str1); gets( str2); gets( str3);...
2019-03-11 23:12:10
2283
原创 输入三个整数,按有小到大的顺序输出(用指针的方法处理)
#include using namespace std; int main() { void swap(intp1,intp2); int n1,n2,n3; int *p1,*p2,*p3; cout<<"请输入三个数字 n1,n2,n3:"; cin>>n1>>n2>>n3; p1=&n1; p2=&n2; p3...
2019-03-11 22:47:16
7016
原创 输出学生成绩(声明一个简单的结构类型表示学生成绩,编写一个函数,将该结构类型变量作为函数的参数)
#include&lt;stdio.h&gt; struct student { char name[20]; float score[3]; }student={“fan”,97.0,97.5f,98.5f}; void Display(struct student stu) { printf(" 信息 \n"); printf(“名字:%s\n”,stu. name); printf(...
2018-12-25 18:07:52
1014
原创 俄罗斯方块的界面设计
#include<stdio.h> #include<time.h> #include<windows.h> #include<conio.h> void gotoxy(int x,int y) { COORD pos; pos.X=x; pos.Y=y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPU...
2018-12-25 15:40:11
1924
原创 动态列表(循环)
#include<stdio.h> #include<stdlib.h> typedef struct student //typedef的功能是对struct student重新命名(STU),用起来方便 { char name[8]; int age; struct student*kd; }STU; void main() { STU*help,*header=NU...
2018-12-25 15:35:34
461
原创 动态列表
#include<stdio.h> #include<stdlib.h> #include<string.h> struct student { char name[8]; int age; struct student*kd; }; void main() { struct student *help,*header=NULL;//malloc功能是动态开辟连...
2018-12-25 15:32:08
291
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅