2020ccpc河南赛ProblemA 班委竞选

签到题

某班级中有 n 位学生,学号为 1, 2, . . . , n。现在班级中正在举行 m 个班干部职位的竞选,职位用 1, 2, . . ., m 编号。学号为 i 的同学竞选的职位为 ci,获得 ti 票。最终每个职位选择票数最高的同学上任, 若存在多个同学票数一致,则选择学号最小的同学上任。 现在给你唱票结果,请你告诉班主任最终的班干部名单。
输入格式
第一行包含两个整数 n, m (1 ≤ n ≤ 51, 1 ≤ m ≤ 12, m ≤ n),含义见题目描述。接下来 n 行,第 i 行包含两个整数 ci, ti (1 ≤ ci ≤ m, 1 ≤ ti ≤ n),含义见题目描述。
数据保证每个职位至少有一位同学参与竞选。
输出格式
输出一行,包含 m 个整数。第 i 个整数表示担任第 i 个班干部职位的同学学号。

思路:
1.开一个足够大的二维数组,一维表示职位,二维表示改职位下的最大票数【1表示职位,2表示人】
2.初始化数组。如果对数组不进行初始化,不会AC。
3.博主从1开始对数组计数。i表示班级人数,每次输入职位t和第i人获得的票数c,如果第i个人的职位c票数小于t,则把此时的票数赋值给该职位,作为最大票,同时记录对应的人。

具体代码如下

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,c,t;
	cin>>n>>m;
	int a[100][2];
	memset(a,0,sizeof(a));
	for(int i=1;i<=n;i++){
		cin>>c>>t;
		if(a[c][1]<t){
			a[c][1]=t;
			a[c][2]=i;
		}
	}
	for(int i=1;i<=m;i++){
		cout<<a[i][2]<<" ";
	}
	return 0;
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
优秀班委选举系统 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); } } } } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值