当前位置: 首页 > news >正文

网站正建设中hao123网址导航

网站正建设中,hao123网址导航,网站推广双鼎,免费建站的方法本人能力有限,发出只为帮助有需要的人。 以下为实验课的复盘,内容会有大量失真,请多多包涵。 1.双手剑士的最优搭配 每把剑有攻击力和防御力两个属性。双手剑士可以同时拿两把剑,其得到攻击力为两把剑中的攻击力的最大值&#…

本人能力有限,发出只为帮助有需要的人。

以下为实验课的复盘,内容会有大量失真,请多多包涵。

1.双手剑士的最优搭配

每把剑有攻击力和防御力两个属性。双手剑士可以同时拿两把剑,其得到攻击力为两把剑中的攻击力的最大值,防御力为两把剑中的防御力的最小值。现在想让双手剑士的攻击力和防御力之和最大。输入n作为剑的个数,再输入2n分别对应每把剑的攻击力和防御力,要求输出最优解为哪两把剑(当攻击力和防御力之和相同时优先选择编号靠前的两把剑)

输入:3 10 4 5 10 7 8

输出:1 2

题解为

#include <stdio.h>
int max(int x,int y)//最大值函数
{if(x>y)return x;return y;
}
int min(int x,int y)//最小值函数
{if(x<y)return x;return y;
}
int main(void)
{int a[100][1]={0},n;//设置二维数组scanf("%d",&n);for(int i=0;i<n;i++)scanf("%d %d",&a[i][0],&a[i][1]);//a[i][0]为攻击力,a[i][1]为防御力int maxSum=0,attack=0,defend=0;int x,y;for(int i=0;i<n;i++)//二重循环遍历{for(int j=i+1;j<n;j++){defend=min(a[i][1],a[j][1]);attack=max(a[i][0],a[j][0]);if(defend+attack>maxSum){maxSum=defend+attack;//找当前的最优解x=i;y=j;//用x,y记录}}}printf("%d %d",x+1,y+1);//注意此题从1开始计数return 0;
}

2.一列数转化二级制中1的个数(11.17)

输入一个正整数n,之后输入n个非负整数组成一个数组,将数组中的每个元素转化成二进制数,输出数组中每个二进制数中1的个数,输出每个数前有一个空格

样例:
输入:5 1 2 3 4 5

输出: 1 1 2 1 2

#include <stdio.h>
int main(void)
{int n,i,a[100],b[100],flag;scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&a[i]);for(i=0;i<n;i++){flag=0;while(a[i]!=0)//将数组的数字化成二进制{if(a[i]%2==1)flag++;//计算二进制中1的数量a[i]/=2;b[i]=flag;//用两个数组}}for(i=0;i<n;i++)printf(" %d",b[i]);return 0;
}

3.一周中的下一个热天(11.10)

向一个长度为7的数组中输入七天的气温(范围为-10到+10)

找到每天以后更热(温度大于此天)的一天,输出其间隔的天数

样例(题目所给样例忘了,这个是新编的)

输入1 1 -1 2 3 1 4

输出3 2 1 1 2 1 0

原题如下

#include <stdio.h>
#include <stdlib.h>int main(void)
{int temperature[7],i,j;for(i=0;i<7;i++)scanf("%d",&temperature[i]);int days[7]={0};for(i=0;i<7;i++)/**/for(i=0;i<7;i++)printf("%d ",days[i]);return 0;
}

解答

#include <stdio.h>
#include <stdlib.h>int main(void)
{int temperature[7],i,j;for(i=0;i<7;i++)scanf("%d",&temperature[i]);int days[7]={0};//考了数组初始化,但对此题的作答无影响for(i=0;i<7;i++){int flag=0;for(j=i+1;j<7;j++)//两层循环{flag++;if(temperature[j]>temperature[i]){days[i]=flag;//构建新数组break;}}}for(i=0;i<7;i++)printf("%d ",days[i]);return 0;
}

4.删除链表中的重复元素

给出一个结构体链表,包含姓名、学号、年龄三个要素。输入一个n,要求输入n个三要素后,再输入一个数字,删除年龄为这个数字的链表节点,并输出链表。

输入:

3

1 zhangsan 18

2 lisi 19

3 wangwu 18

18

输出

2 lisi 19

原题

#include <stdio.h>
#include <malloc.h>
struct cell
{int x;char name[1000];//字符数字储存姓名int age;struct cell* next;
};struct cell *build(int num)//输入链表
{
/**/
}void print(struct cell* head)//输出链表
{struct cell* p;p=head;while(p!=NULL){printf("%d %s %d\n",p->x,p->name,p->age);p=p->next;}
}
void release(struct cell* head)//释放链表所占用的空间
{struct cell *p,*tmp;p=tmp=head->next;while(p!=NULL){tmp=p;p=p->next;free(tmp);}p=head=tmp=NULL;
}struct cell* delCell(struct cell *head,int n)
{while(head->age==n)//当头节点的值要删除时,将头节点向后挪head=head->next;struct cell *p,*p0;p=head;while(p!=NULL){if(p->age==n)//删除节点的标准操作{p0->next=p->next;p=p0;}p0=p;p=p->next;}return head;
}int main(void)
{struct cell*head;int num,n;scanf("%d",&num);head=build(num);scanf("%d",&n);head=delCell(head,n);print(head);release(head);return 0;
}

题解

#include <stdio.h>
#include <malloc.h>
struct cell
{int x;char name[1000];//字符数字储存姓名int age;struct cell* next;
};struct cell *build(int num)//输入链表
{struct cell *tmp;struct cell *headA = (struct cell*)malloc(sizeof(struct cell));scanf("%d %s %d",&headA->x,headA->name,&headA->age);//注意字符串的输入方法struct cell *end = headA;for(int i=0; i<num-1; i++)//输入num个元素{tmp = (struct cell*)malloc(sizeof(struct cell));scanf("%d %s %d",&tmp->x,tmp->name,&tmp->age);end->next = tmp;end = tmp; }end->next = NULL;return headA;
}void print(struct cell* head)//输出链表
{struct cell* p;p=head;while(p!=NULL){printf("%d %s %d\n",p->x,p->name,p->age);p=p->next;}
}
void release(struct cell* head)//释放链表所占用的空间
{struct cell *p,*tmp;p=tmp=head->next;while(p!=NULL){tmp=p;p=p->next;free(tmp);}p=head=tmp=NULL;
}struct cell* delCell(struct cell *head,int n)
{while(head->age==n)//当头节点的值要删除时,将头节点向后挪head=head->next;struct cell *p,*p0;p=head;while(p!=NULL){if(p->age==n)//删除节点的标准操作{p0->next=p->next;p=p0;}p0=p;p=p->next;}return head;
}int main(void)
{struct cell*head;int num,n;scanf("%d",&num);head=build(num);scanf("%d",&n);head=delCell(head,n);print(head);release(head);return 0;
}


 

http://www.shuangfujiaoyu.com/news/45460.html

相关文章:

  • 网站内容侵权 怎么做ai智能搜索引擎
  • 网站怎么做关键词在哪做在广州做seo找哪家公司
  • 西安网站建设首选佛山网站建设维护
  • 企业网站建设制作设计哪家最专业灰色行业推广平台
  • 找公司做网站源代码给客户吗广告联盟怎么加入
  • 珠海网站建seo竞价推广
  • 建设自己的企业网站需要什么资料推广方案
  • 自己做网站上市网站优化排名方案
  • 企业网站seo最好方法百度号码认证平台取消标记
  • 电子政务门户网站建设方案网站seo案例
  • 惠州最专业的网站建设公司游戏推广代理
  • 南京市的网站是由那几家公司做的推广普通话手抄报
  • 企业网站建设专家网络营销策划论文
  • 如何隐藏网站是基于thinkphp做的重庆网站建设技术外包
  • 凡科网电脑版怎么做网站优化营商环境条例
  • 米拓网站建设步骤360关键词指数查询
  • 广东省住房与城乡建设厅网站同仁seo排名优化培训
  • 阿里云网站备案多久seo标签优化
  • 做网站推广托管费用百度旗下所有app列表
  • 网站设计的公司成人教育培训机构排名
  • 网站rss地址生成国内最新新闻事件今天
  • 做视频大赛推广的网站长春模板建站代理
  • zblog网络优化工程师是做什么的
  • 杭州网站开发公司最新中国新闻
  • 网站移动页面怎么做济宁百度推广公司
  • 陕西省住房城乡建设部门户网站网站怎么优化排名靠前
  • 网站策划方案ppt环球网
  • 汽车网站策划网络营销主要有哪些特点
  • 互动网页设计qq排名优化网站
  • 企业网站建设和管理买域名要多少钱一个