最大访客数(c/python)
来源:互联网 发布:淘宝店铺升级在哪里 编辑:程序博客网 时间:2024/05/29 19:55
说明:确定某一时间的最大容客量,用X[i],y[i]分别表示第i个访客来访和离开的时间;
c代码
#include<stdio.h>#include<stdlib.h>#define N 100void sort(int *, int);int main(){ int i, j; int number = 0; int x[N] = { 0 }; int y[N] = { 0 }; printf("输入访客来访与离开的时间(0~24):"); for (i = 0; i < N; i++) { printf("\n"); scanf_s("%d%d", &x[i], &y[i]); printf("\n"); //输入(-1,-1)终止 if (x[i] < 0 || y[i] < 0) break; } sort(x, i); sort(y, i); for (int time = 1; time <= 24; time++) { number = 0; for (j = 1; j <= i; j++) //如果不对x[i],y[i]进行排序改成for(j=0;j<i,j++) { if (time > x[j]) number++; if (time > y[j]) number--; } printf("%d时的最大访客数为%d\n", time, number); } system("pause");}void sort(int *arr, int n){ //int min = 0; int temp; for (int i = 0; i < n; i++) { int min = i; //temp = arr[min]; for (int j = i + 1; j <= n; j++) { if (arr[j] < arr[min]) { temp = arr[min]; arr[min] = arr[j]; arr[j] = temp; } } }}
python
# -*- coding: utf-8 -*-"""Created on Sat Nov 4 20:22:59 2017@author: yangwenbin"""#import numpy as npdef sort(arr,n): for i in range(n): Min=i for j in range(i+1,n+1): if arr[Min]>arr[j]: temp=arr[Min] arr[Min]=arr[j] arr[j]=temp pass pass pass passif __name__=="__main__": x=[0]*100 y=[0]*100 print("请输入来访离开时间:") for i in range(100): x[i]=int(input()) y[i]=int(input()) if x[i]<0 or y[i]<0: break pass sort(x,i) sort(y,i) for time in range(1,25): num=0 for j in range(1,i+1): if time>x[j]: num+=1 pass if time>y[j]: num-=1 pass pass print("%d时最大访客数%d"%(time,num)) pass pass
阅读全文
0 0
- 最大访客数(c/python)
- 最大访客数
- Algorithm Gossip: 最大访客数
- Algorithm Gossip (21) 最大访客数
- python排列最大数
- python建立访客记录
- WordPress 站点统计访客数
- C#--求三个数的最大数
- leetcode_[python/C++] 179. Largest Number(数字组合成最大数)
- 阿姆斯壮数(c/python)
- 访客
- 一个显示访客数的例子
- [C]选出三个数中的最大数和最小数
- python 中最大,最小数的问题
- 纯C语言:递归最大数源码
- c语言(判断最大数)
- 三个数a,b,c找出最大数
- C++:比较三个数的大小,找出最大数
- SSH密钥远程登陆
- 转:Python中的sorted函数以及operator.itemgetter函数
- [IMX6Q]uboot_v2015.04编译流程分析
- JAVA中ListIterator和Iterator详解与辨析
- [BFS] HDU 2102
- 最大访客数(c/python)
- stackoverflow那些有趣的badges
- 国内云市场的发展前景
- mysql 单表更新和多表更新
- Exception sending context initialized event to listener instance of class org.springframework.web.co
- 平安城市,路不拾遗、夜不闭户的“大同”世界
- 心得
- 初识android HAL
- git使用中遇到的remote:Permission to xxx denied to xxx问题如何解决