#include
#include
#include <string.h>
using namespace std;
double sum(int n){
int i=1;
double sum=1;
double j;
for (j = 2; j <=n ; j++) {
i=-i;
sum += i/j;
}
return sum;
}
void yanghui(){
//默认为0
int a[6][11]={0};
//两个for循环
for (int i = 0; i < 6; ++i) {
for (int j = 5-i; j <= 5+i; ++j) {
//三角形边1赋值完成
if (i+j5||ij-5){
a[i][j]=1;
}
//给非1部分且左边为0的部分(也就是与上一行刚好交叉的位置)赋值
if (a[i][j-1]==0&&a[i][j]!=1){
a[i][j]=a[i-1][j-1]+a[i-1][j+1];
}
}
}
//打印二维数组
for (int i = 0; i < 6; ++i) {
for (int j = 0; j < 11; ++j) {
if (a[i][j]==0){
cout<<" ";
} else{
cout<<a[i][j];
}
}
cout<<endl;
}
}
//读取指定文件内容并操作
void mergeFile(){
//定义文件工作指针
FILE *fa,*fb,*fc;
//字符工作指针
char ch;
fa=fopen(“C:\Users\15023\Desktop\a.txt”,“r+”);
fb=fopen(“C:\Users\15023\Desktop\b.txt”,“r”);
fc=fopen(“C:\Users\15023\Desktop\c.txt”,“r+”);
//判断所处理文件是否存在
if (faNULL||fbNULL){
cout<<“文件不能打开!”<<endl;
return;
}
//读取a、b先写入c
while(!feof(fa)){//feof文件结束返回1,没结束返回0;(特别注意)
ch=fgetc(fa);
fputc(ch,fc);
if (!feof(fb)){
ch=fgetc(fb);
fputc(ch,fc);
}
}
while (!feof(fb)){
ch= fgetc(fb);
fputc(ch,fc);
}
rewind(fa);
rewind(fc);
while(!feof(fc)){
ch= fgetc(fc);
fputc(ch,fa);
}
fclose(fa);
fclose(fb);
fclose(fc);
}
//小球下落
double count=0;
void drop(double dis,int i,int x){
count+=dis;
if (ix){
printf(“第%d次反弹高度为:%f,所经过路径为:%f”,i,dis,count);
return;
}
i++;
dis =dis/2;
drop(dis,i,x);
}
//求两个日期相隔天数
//该日期为该年的第几天
int nleap_year(int n,int y,int r){
int data[]={31,59,90,120,151,181,212,243,273,304,334,365};
if (y1){
return r;
}
if (y>1&&y<13){
if ((n%40&&n%100!=0)||n%4000){
return data[y-2]+r+1;
} else{
return data[y-2]+r;
}
}
}
void judge(){
int n,y,r;
printf(“请输入年月日:”);
scanf("%d,%d,%d",&n,&y,&r);
int data1=nleap_year(n,y,r);
printf(“请再输入同年月日:”);
scanf("%d,%d",&y,&r);
int data2=nleap_year(n,y,r);
printf(“相差%d天;”,data2-data1);
}
//字串在母串中出现次数
void search(){
char a[]=“string”;
char b[]=“sstringdstringfstring”;
int j=0;
int count=0;
while(b[j]!=’\0’){
int i=0;
while (a[i]!=’\0’){
if(b[j]==a[i]){
i++;
j++;
} else{
break;
}
}
}
}
//递归输出到文件
char digui(char a[],int i,FILE *p){
if(a[i]!=’\n’){
i++;
digui(a,i,p);
fputc(a[i-1],p);
}
}
void output(){
printf(“请输入字符:”);
char a[20];
gets(a);
FILE *p;
p= fopen(“C:\Users\15023\Desktop\a.txt”,“w”);
digui(a,0,p);
fclose§;
}
//学生结构体
void text(){
char a[]=“123124”;
char b[]=“12312”;
if (strcmp(a,b)==0){
cout<<“sdfsdf”;
} else{
cout<<“sdf”;
}
}
//2015------------------------------------------------------------------------------
//黑色星期五
void black(int year){
//即判断每个月的第13天是否是5+7T
int data[]={0,31,59,90,120,151,181,212,243,273,304,334};
int data2[]={0,31,60,91,121,152,182,213,244,274,305,336};
if ((year%4==0&&year%100!=0)||year%400==0){
for (int i = 0; i <12; ++i) {
if ((365*year+year/4-year%100+year/400+data[i]+13)%7==5){
printf("黑色星期五为:%d年%d月%d日",year,i+1,13);
}
}
} else{
for (int i = 0; i <12; ++i) {
if ((365*year+year/4-year%100+year/400+data2[i]+13)%7==5){
printf("黑色星期五为:%d年%d月%d日",year,i+1,13);
}
}
}
}
//删除公共元素
typedef struct LNode{
char data;
struct LNode *next;
}LNode,*LinkList;
LinkList initLinkList1(){
//头结点
LNode *L=(LinkList) malloc(sizeof (LNode));
//L->data=NULL;//头结点data不用管,只让->next=NULL;就行
//数据结点
LNode *b=(LinkList) malloc(sizeof (LNode));
b->data=1;
LNode *c=(LinkList) malloc(sizeof (LNode));
c->data=2;
LNode *d=(LinkList) malloc(sizeof (LNode));
d->data=3;
LNode *e=(LinkList) malloc(sizeof (LNode));
e->data=4;
LNode *f=(LinkList) malloc(sizeof (LNode));
f->data=5;
L->next=b;b->next=c;c->next=d;d->next=e;e->next=f;f->next=NULL;
return L;
}
LinkList initLinkList2(){
//头结点
LNode *L=(LinkList) malloc(sizeof (LNode));
//L->data=NULL;//头结点data不用管,只让->next=NULL;就行
//数据结点
LNode *b=(LinkList) malloc(sizeof (LNode));
b->data=1;
LNode *c=(LinkList) malloc(sizeof (LNode));
c->data=3;
LNode *d=(LinkList) malloc(sizeof (LNode));
d->data=5;
LNode *e=(LinkList) malloc(sizeof (LNode));
e->data=7;
LNode *f=(LinkList) malloc(sizeof (LNode));
f->data=8;
L->next=b;b->next=c;c->next=d;d->next=e;e->next=f;f->next=NULL;
return L;
}
LinkList initLinkList3(){
//头结点
LNode *L=(LinkList) malloc(sizeof (LNode));
//L->data=NULL;//头结点data不用管,只让->next=NULL;就行
//数据结点
LNode *b=(LinkList) malloc(sizeof (LNode));
b->data=1;
LNode *c=(LinkList) malloc(sizeof (LNode));
c->data=2;
LNode *d=(LinkList) malloc(sizeof (LNode));
d->data=3;
LNode *e=(LinkList) malloc(sizeof (LNode));
e->data=4;
LNode *f=(LinkList) malloc(sizeof (LNode));
f->data=5;
L->next=b;b->next=c;c->next=d;d->next=e;e->next=f;f->next=NULL;
return L;
}
void deletecommon(LinkList &a,LinkList &b,LinkList &c){
//工作指针
LNode *pre=a,*pa=pre->next,*pb=b->next,*pc=c->next,*temp;
while(pa){
while(pa->data>pb->data){
pb=pb->next;
}
if (pa->datapb->data){
//去c里找是否存在该元素
while (pa->data>pc->data){
pc=pc->next;
}
if (pa->datapc->data){
//bc都存在则删除
temp=pa;
pre->next=pa->next;
//删除操作已经将a前移了不用再移动了
pa=pa->next;
free(temp);
} else{
pre=pre->next;pa=pre->next;
}
} else{
pre=pre->next;pa=pre->next;
}
}
}
/2.3打印链表/
void print_L(LinkList L){
LinkList p=L->next;
while (p!=NULL){
cout<<"{"<data<<"},";
p=p->next;
}
cout<<endl;
}
/删除单链表重复值/
LinkList initLinkList4(){
//头结点
LNode *L=(LinkList) malloc(sizeof (LNode));
//L->data=NULL;//头结点data不用管,只让->next=NULL;就行
//数据结点
LNode *b=(LinkList) malloc(sizeof (LNode));
b->data=1;
LNode *c=(LinkList) malloc(sizeof (LNode));
c->data=2;
LNode *d=(LinkList) malloc(sizeof (LNode));
d->data=1;
LNode *e=(LinkList) malloc(sizeof (LNode));
e->data=1;
LNode *f=(LinkList) malloc(sizeof (LNode));
f->data=3;
L->next=b;b->next=c;c->next=d;d->next=e;e->next=f;f->next=NULL;
return L;
}
void deleteNode(LinkList &L){
LNode *p=L->next,*q,*pre,*temp;
q=p->next;pre=p;
while §{
while (q){
if (p->data==q->data){
temp=q->next;
pre->next=q->next;
free(q);
q=temp;
} else{
pre=pre->next;
q=pre->next;
}
}
p=p->next;
pre=p;
q=pre->next;
}
}
//括号匹配
int main() {
//分数数列和
/int a[2][3]={0};
int n;
cout<<“请输入序列个数:”<<endl;
cin>>n;
double res=sum(n);
cout<<res<<endl;/
//杨辉三角
/yanghui();/
//小写转换大写并写入文件
/char str[100];
FILE p;
int i,len=0;
printf(“输入一串英文字符:\n”);
while((str[len]=getchar())!=’\n’)
{
len++;
}
for(i=0;i<len;i++){
if(str[i]>=‘a’&&str[i]<=‘z’)
str[i]-=32;
}
p=fopen(“C:\Users\15023\Desktop\test.txt”,“w”);
fputs(str,p);
fclose§;/
//输入某年某月某日判断为第几天
/int year;cin>>year;
int month;cin>>month;
int day;cin>>day;
int list[12]={31,60,91,121,152,182,213,244,274,305,335,366};
int count;
if(month==1){
count = day;
}
if ((year % 4 == 0&&year % 100 != 0)||year % 400 == 0){
if(month > 1 && month<13)
count = list[month-2] + day;
}else{
if (month > 1 && month < 13)
count = list[month - 2] + day-1;
}
cout<<“第”<<count<<“天!”<<endl;/
//文件的简单归并且
/mergeFile();/
/int a,b,c;
scanf("%d,%d,%c",&a,&b,&c);
printf(“a的值是:%d,b的值是:%d值之间没有”,“号:%c”,a,b,c);
char as[]=“12312”;
string aa=“adsfsadfs”;
cout<<as<<aa;/
//小球反弹高度
/
drop(200,1,8);
*/
//判断两个日期相差天数
/judge();/
/search();/
//递归输入文件
/output();/
//对输入字符串进行冒泡排序;
//黑色星期五
/*black(2021);*/
//删除链表公共元素
/* LinkList l1=initLinkList1();
LinkList l2=initLinkList2();
LinkList l3=initLinkList3();
deletecommon(l1,l2,l3);
print_L(l1);
cout<<“sdfas深度”;*/
LinkList l=initLinkList4();
print_L(l);
deleteNode(l);
print_L(l);
return 0;
}
-----------------------------------------------------2021年考研的时光-----22age