Day 3 算法笔记之习题集2.7
2021/9/14 22:05:13
本文主要是介绍Day 3 算法笔记之习题集2.7,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1.C语言10.1
这里面用了一个挺有趣的式子 ()?a:b,判断起来满简洁的。
#include<cstdio> #include<cstring> int main(){ int a,b; int *m=&a,*n=&b; scanf("%d %d",m,n); printf("%d %d",*m>*n?*m:*n,*m>*n?*n:*m); return 0; }
2.C语言10.2
#include<cstdio> #include<cstring> int main(){ int a,b,c; int *x=&a,*y=&b,*z=&c; scanf("%d %d %d",x,y,z); int martix[10] = {*x,*y,*z}; for (int i=0; i<2; i++){ for(int j=0; j<2-i;j++){ if (martix[j]<martix[j+1]){ int temp = martix[j]; martix[j] = martix[j+1]; martix[j+1] = temp; } } } for (int i=0; i<3; i++){ printf("%d ",martix[i]); } return 0; }
3.C语言10.10
#include<cstdio> #include<cstring> int main(){ const char *a = "I love China!"; int x; scanf("%d",&x); printf("%s",a+x); return 0; }
4.C语言10.15
就贴个代码在这了,没啥意思,也没做完,后面的是体力活。不过后面大佬的写法还是值得一看的。
#include<cstdio> #include<cstring> int main(){ char martix_1[100],martix_2[100],martix_3[100]; char *x=martix_1,*y=martix_2,*z=martix_3; int length_1,length_2,length_3; scanf("%s",x); scanf("%s",y); scanf("%s",z); for(int i=0; i< strlen(martix_1);i++){ printf("%d\n",*(x+i)); length_1+=*(x+i); } printf("----------------------------%d\n",length_1); for(int i=0; i< strlen(martix_2);i++){ printf("%d\n",*(y+i)); length_2+=*(y+i); } printf("----------------------------%d\n",length_2); for(int i=0; i< strlen(martix_3);i++){ printf("%d\n",*(z+i)); length_3+=*(z+i); } printf("----------------------------%d\n",length_3); printf("%d %d %d",length_1,length_2,length_3); return 0; } //#include <cstdio> //#include <cstring> //int main() //{ // char a[20],b[20],c[20]; // char *p=a,*q=b,*r=c; // scanf("%s%s%s",a,b,c); // printf("%s\n%s\n%s\n",strcmp((strcmp(p,q)>0?q:p),r)<0?(strcmp(p,q)>0?q:p):r, // strcmp((strcmp(p,q)>0?p:q),r)>0?(strcmp((strcmp(p,q)>0?q:p),r)>0?(strcmp(p,q)>0?q:p):r):(strcmp(p,q)>0?p:q), // strcmp((strcmp(p,q)>0?p:q),r)>0?(strcmp(p,q)>0?p:q):r); // return 0; //}
5.C语言10.16
这一个其实做的相当烦躁,女朋友一直在逼逼赖赖,不过这题练习指针还是相当不错的
#include<cstdio> #include<cstring> int* return_min(int a[]){ int min=0; for(int i=1;i<10;i++){ if(a[min]>a[i]){ min=i; } } return &a[min]; } int* return_max(int a[]){ int max=0; for(int i=1;i<10;i++){ if(a[max]<a[i]){ max=i; } } return &a[max]; } void swap(int*p,int*q){ int temp=*p; *p=*q; *q=temp; } int main(){ int martix[100]; for(int i=0;i<10;i++){ scanf("%d",&martix[i]); } int *p,*q; p =return_min(martix); q =return_max(martix); swap(p,&martix[0]); swap(q,&martix[9]); for(int i=0;i<10;i++){ printf("%d ",martix[i]); } return 0; }
这篇关于Day 3 算法笔记之习题集2.7的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?