1001.选班长

班级正在选举班长,有n(n≤999)名候选人,每名候选人编号分别从 1 到 �n,现在收集到了m(m≤2000000)张选票,每张选票都写了一个候选人编号。现在想把这些堆积如山的选票按照投票数字从小到大排序并写出选举票数最多的序号。

输入格式

第一行为�n �m

第二行为�m张票 中间用空格隔开

输出格式

第一行为排好序的投票结果(中间用空格隔开)

第二行为选中的序号

样例

输入

5 10
2 5 2 2 5 2 2 2 1 2

输出

1 2 2 2 2 2 2 2 5 5
2

数据范围

1≤n≤999

1≤m≤2000000

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;
const int N = 2e5 + 10;
int n, m, k = 0;
int a[N];
int main()
{
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> k;
        a[k]++;
    }
    int max = a[0];
    int c = 0;
    for (int i = 1; i <= n; i++)
        if (max < a[i])
        {
            max = a[i];
            c = i;
        }
    for (int i = 1; i <= n; i++)
        for (int j = 0; j < a[i]; j++)
            cout << i << " ";
    cout << endl;
    cout << c;
    return 0;
}

器件名称规格 数量(根据电路图择芯片数量) 备注 可器件 74LS00 2输入端4与非门 74LS04 6非门 74LS08 2输入端4与门 74LS20 4输入与非门 74LS32 2输入或门 74LS86 四异或门 74LS74 双D触发器 74LS138 3-8译码器 74LS139 2-4译码器 74LS151 81数据择器 74LS161 四位二进制加法计数器 74LS190 可预置数BCD加减计数器 74LS193 可预置数四位二进制可逆计数器 74LS194 多功能移位计数器 74LS374 三态8D触发器 74LS279 RS触发器(可用来去抖) 发光二极管 红/黄/绿 CD4511 七段显示译码器 74LS90 BCD加法计数器 IC座14脚 IC座16脚 IC座20脚 定量器件和工具(班长或者学委代领) 开关(自锁) 1 开关(不自锁) 3 2位共阴数码管 3 2位共阴数码管 IC座24脚(宽) 3 插数码管 220Ω左右 3 数码管限流电阻 20M电阻 1 晶振起振 晶振32768Hz 1 秒脉冲 可调电容30-50P 2 晶振起振 CD4060 1 分频器 直流小电机(130电机2cm长轴)及配套小齿轮 1 择测速题目的才需要 红外对管 1 择测速题目的才需要 收纳箱 1 每组用来装万用表、起拔器、吸锡带、一字批、松香、海绵、电路板及每组所需的IC插座芯片等材料。(组长领取) 恒温焊台 1 焊锡 每班1卷 导线 每班2卷 电路板 1块 12cm×18cm USB连接线 1套 接电源正负极 万用表 1块 根据以上元器件,做出一个数字中电路系统,并用multisim模拟,要求设计制作一个数字电子钟。 时间计数电路采用24进制,从00开始到23后再回到00; 各用2位数码管显示时、分、秒; 2、具有手动校时、校分功能,可以分别对时、分进行单独校正; 3、计时过程具有报时功能,当时间到达整点前10秒开始,蜂鸣器响1秒停1秒地响5次; 4、采用软件仿真
05-14
优秀班委举系统 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace 优秀班委举 { public partial class Form1 : Form { private ListBox listBox; public Form1() { InitializeComponent(); } public Form1(ListBox listBox) { InitializeComponent(); this.listBox = listBox; } private void button1_Click(object sender, EventArgs e) { if (listBox1.Items.Count > 0) { if (listBox1.SelectedItem == null) { MessageBox.Show("请先择一个对象!"); } else { //获取左边listBox1中中的内容 string cont = listBox1.SelectedItem.ToString(); //左边listBox1中删除中的内容 listBox1.Items.Remove(cont); //把获得的内容加入到右边的listBox2中 listBox2.Items.Add(cont); } } } private void button2_Click(object sender, EventArgs e) { if (listBox2.Items.Count > 0) { if (listBox2.SelectedItem == null) { MessageBox.Show("请先择一个对象!"); } else { //获取右边listBox2中中的内容 string cont = listBox2.SelectedItem.ToString(); //右边listBox2中删除中的内容 listBox2.Items.Remove(cont); //把获得的内容加入到左边的listBox1中 listBox1.Items.Add(cont); } } } //退出 private void button5_Click(object sender, EventArgs e) { Application.Exit(); } //显示结果 private void button4_Click(object sender, EventArgs e) { //传递listBox2到Form2窗口中 Form2 form2 = new Form2(listBox2); form2.Show(); } //修改名单 private void button3_Click(object sender, EventArgs e) { if (listBox2.SelectedItem == null) { MessageBox.Show("请先择一个对象!"); } else { string cont = listBox2.SelectedItem.ToString(); int index = listBox2.SelectedIndex; Form3 form3 = new Form3(cont, index, listBox2); form3.Show(); this.Hide(); } } //加载窗口 private void Form1_Load(object sender, EventArgs e) { if (listBox != null) { foreach (string str in listBox.Items) { listBox2.Items.Add(str); } } } } }
以下是一个简单的班长投票系统的Java代码示例: 首先是班级和候人的类定义: ```java public class Student { private String name; private int id; private int votes; public Student(String name, int id) { this.name = name; this.id = id; this.votes = 0; } public String getName() { return name; } public int getId() { return id; } public int getVotes() { return votes; } public void addVote() { votes++; } } public class Class { private ArrayList<Student> students; private Student president; public Class() { this.students = new ArrayList<Student>(); this.president = null; } public void addStudent(Student student) { students.add(student); } public ArrayList<Student> getStudents() { return students; } public void vote(int id) { Student candidate = null; for (Student student : students) { if (student.getId() == id) { candidate = student; break; } } if (candidate != null) { candidate.addVote(); if (president == null || candidate.getVotes() > president.getVotes()) { president = candidate; } } } public Student getPresident() { return president; } } ``` 然后是一个简单的控制台应用程序,用于演示投票过程: ```java import java.util.Scanner; public class Main { public static void main(String[] args) { Class class1 = new Class(); class1.addStudent(new Student("Tom", 1)); class1.addStudent(new Student("Jack", 2)); class1.addStudent(new Student("Mary", 3)); Scanner scanner = new Scanner(System.in); while (true) { System.out.println("Please enter the ID of the candidate you want to vote for:"); int id = scanner.nextInt(); if (id < 1 || id > 3) { System.out.println("Invalid ID."); continue; } class1.vote(id); System.out.println("Thank you for voting."); System.out.println("Current vote counts:"); for (Student student : class1.getStudents()) { System.out.println(student.getName() + ": " + student.getVotes()); } if (class1.getPresident() != null) { System.out.println("Current president: " + class1.getPresident().getName()); } } } } ``` 在这个应用程序中,首先创建了一个班级对象,然后向其中添加了三个学生对象作为候人。在控制台中循环读取用户输入的候人ID,并调用班级对象的投票方法进行投票。投票结束后,输出当前的票数和领导人信息。在实际应用中,可以将投票系统与GUI界面等其他组件结合起来,提供更友好的用户体验。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

墨墨祺

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值