2403. Voting || string

2403. Voting

Constraints

Time Limit: 1 secs, Memory Limit: 256 MB

Description

A committee clerk is good at recording votes, but not so good at counting and figuring the outcome correctly.  As a roll call vote proceeds, the clerk records votes as a sequence of letters, with one letter for every member of the committee:

Y means a yes vote
N means a no vote
P means present, but choosing not to vote
A indicates a member who was absent from the meeting
 
Your job is to take this recorded list of votes and determine the outcome.
Rules:   
There must be a quorum.  If at least half of the members were absent, respond "need quorum".  Otherwise votes are counted.   If there are more yes than no votes, respond "yes".   If there are more no than yes votes, respond "no".   If there are the same number of yes and no votes, respond "tie". 

Input

The input contains of a series of votes, one per line, followed by a single line with the # character. Each vote consists entirely of the uppercase letters discussed above.  Each vote will contain at least two letters and no more than 70 letters.

Output

For each vote, the output is one line with the correct choice "need quorum", "yes", "no" or "tie".

Sample Input

YNNAPYYNY
YAYAYAYA
PYPPNNYA
YNNAA
NYAAA
#

Sample Output

yes
need quorum
tie
no
need quorum

Problem Source

每周一赛第四场


代码:

#include <iostream>
#include <string>

using namespace std;

int main () {
	string vote;
	while (cin>>vote && vote != "#") {
		int yes = 0;
		int no = 0;
		int abs = 0;
		for (int i = 0; i < vote.length(); i++) {
			if (vote[i] == 'Y')
				yes++;
			if (vote[i] == 'N')
				no++;
			if (vote[i] == 'A')
				abs++;
		}
		if (2*abs >= vote.length())
			cout<<"need quorum";
		else {
			if (yes > no)
				cout<<"yes";
			if (no > yes)
				cout<<"no";
			if (yes == no)
				cout<<"tie";
		}
		cout<<endl;
	}
	
	//system("pause");
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的使用Java实现投票的示例程序: ```java import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class VotingSystem { public static void main(String[] args) { Map<String, Integer> candidates = new HashMap<String, Integer>(); Scanner scanner = new Scanner(System.in); System.out.print("Enter the number of candidates: "); int numCandidates = scanner.nextInt(); scanner.nextLine(); // consume the newline character left by nextInt() for (int i = 1; i <= numCandidates; i++) { System.out.print("Enter the name of candidate " + i + ": "); String name = scanner.nextLine(); candidates.put(name, 0); } while (true) { System.out.print("Enter your vote (or 'done' to finish voting): "); String vote = scanner.nextLine(); if (vote.equals("done")) { break; } if (!candidates.containsKey(vote)) { System.out.println("Invalid vote."); } else { candidates.put(vote, candidates.get(vote) + 1); } } int maxVotes = 0; String winner = ""; for (String candidate : candidates.keySet()) { int votes = candidates.get(candidate); if (votes > maxVotes) { maxVotes = votes; winner = candidate; } System.out.println(candidate + ": " + votes + " votes"); } System.out.println("Winner: " + winner); } } ``` 此程序首先要求输入候选人的数量和姓名,然后要求逐个输入投票,直到输入“done”为止。程序会在每次投票后更新每个候选人的票数,并在投票结束后输出每个候选人的票数和最终获胜者的姓名。 请注意,此程序仅用于演示目的,并不具备安全性和可扩展性。在实际应用中,需要考虑更多的因素,例如选民身份验证、防止重复投票等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值