HDU 1084 What Is Your Grade?

题目网站: http://acm.hdu.edu.cn/showproblem.php?pid=1084
      很多人说这是一道水题,但是我却步步维艰,这却是一道水题,却耗了我一天,如果你也被这道题所困扰,希望我的失败能给你提供一些帮助,首先理解一下题目的大义  
       老师要通过五道题给大家评分,做对5道题的,无论时间有多少,都可以得100分,而答对0道题的,无论时间多长都是50分,当你答对四道题,若你在先答对四道题的一半人中(若有3人答对,只能有一人,5人答对,只能有2人),恭喜你,你可获得95分,3.2.1道题以此类推
       我之前给自己草稿的时候分成了四步
                        1.输入处理 :while(scanf  != EOF && 
                        2.记录所用时间和排名 :a[i].time h*3600 m*60 +s;
                                                                    a[i].rank ++max[a.problem];
                       3.冒泡排序rank
                       4.输出 switch(输出项有多项)
       结果是消耗我一天都是WA(wrong anser),原因就是在排序上,我原本以为,如果a用时大于b,且a排名小于b;就交换排名。但不管怎么交换都是徒劳无功的,因为我比较的是时间,交换的是排名!!!最后为了整体的代码,取消了排序,改成了++,果然皇天不负有心人,T  Aceppted

       厌倦了没有注释的代码,现附上一份注释的代码,大家一起共勉吧!

#include<stdio.h>
typedef struct Student
{
	int time;//用来存储所花的总时间
	int problem;//答对的问题数
	int rank;//按时间多少的排名
} student;
int main()
{
	int n,h,m,s;//时分秒
	while(scanf("%d",&n) != EOF && n > 0)
	{
		student a[105];
		int max[6] = {0};//做对1~5题的人数各有多少
		for(int i = 0; i < n; i++)//输入
		{
			scanf("%d%d:%d:%d",&a[i].problem, &h, &m, &s);
			a[i].time = h*3600 + m*60 + s;//便于比较
			max[a[i].problem]++;
			a[i].rank = 1;//所有排名为1,为后面加做铺垫
		}
		for(int i = 0; i < n; i++)
			for(int j = i + 1; j < n; j++)
			{
				if(a[i].problem == a[j].problem)//如果两人答对的问题一样,则进行如下操作
				{
					if(a[i].time > a[j].time) a[i].rank ++;
					else a[j].rank++;//如果我用时比你多,我rank++,否则你rank++
				}
			}
			for(int i = 0; i < n; i++)//输出
				switch (a[i].problem){
				case 5 : printf("%d/n",100); break;
				case 4 :if(a[i].rank > max[4]/2) printf("%d/n",90);
						else printf("%d/n",95); break;
				case 3 :if(a[i].rank > max[3]/2) printf("%d/n",80);
						else printf("%d/n",85); break;
				case 2 :if(a[i].rank > max[2]/2) printf("%d/n",70);
						else printf("%d/n",75); break;
				case 1 :if(a[i].rank > max[1]/2) printf("%d/n",60);
						else printf("%d/n",65); break;
				case 0 : printf("%d/n",50); break;
			}
			printf("/n");
	}
	return 0;
}


      
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,HDU1622是一道关于二叉树的题目,要求读入一系列二叉树的节点信息,输出它们的层序遍历结果。如果输入的二叉树不完整或存在重复节点,则输出"not complete"。下面是Java的实现代码: ```java import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Main { static class Node { int val; Node left, right; public Node(int val) { this.val = val; } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String s = sc.nextLine(); if (s.isEmpty()) { continue; } String[] nodes = s.split("\\s+"); Node root = new Node(Integer.parseInt(nodes[0].substring(1))); Queue<Node> queue = new LinkedList<>(); queue.offer(root); boolean isComplete = true; for (int i = 1; i < nodes.length - 1; i += 2) { Node cur = queue.poll(); if (!nodes[i].equals("()")) { cur.left = new Node(Integer.parseInt(nodes[i].substring(1))); queue.offer(cur.left); } else { isComplete = false; } if (!nodes[i + 1].equals("()")) { cur.right = new Node(Integer.parseInt(nodes[i + 1].substring(0, nodes[i + 1].length() - 1))); queue.offer(cur.right); } else { isComplete = false; } } if (!isComplete) { System.out.println("not complete"); continue; } StringBuilder sb = new StringBuilder(); queue.offer(root); while (!queue.isEmpty()) { Node cur = queue.poll(); sb.append(cur.val).append(" "); if (cur.left != null) { queue.offer(cur.left); } if (cur.right != null) { queue.offer(cur.right); } } System.out.println(sb.toString().trim()); } } } ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值