zoukankan      html  css  js  c++  java
  • HD-ACM算法专攻系列(17)——find your present (2)

    题目描述:

     

    源码:

    #include"iostream"
    #include"string"
    using namespace std;
    
    bool IsFirstHalf(string *strs, int n, string str)
    {
    	int count = 0;
    	for(int i = 0; i < n; i++)
    	{
    		if(str < strs[i])count++;
    	}
    	return count >= (n / 2 + n % 2);
    }
    
    int main()
    {
    	int n, count[100], counts[5];
    	string **strs;
    	strs = new string*[5];
    	for(int i = 0; i < 5; i++)
    	{
    		strs[i] = new string[100];
    	}
    	while(cin>>n)
    	{
    		if(n < 0)break;
    		counts[1] = counts[2] = counts[3] = counts[4] = 0;
    		for(int i = 0; i < n; i++)
    		{
    			cin>>count[i]>>strs[0][i];
    			if(count[i] > 0 && count[i] < 5)
    			{
    				strs[count[i]][counts[count[i]]++] = strs[0][i];
    			}
    		}
    		for(int i = 0; i < n; i++)
    		{
    			switch(count[i])
    			{
    				case 5:
    					cout<<100<<endl;
    					break;
    				case 0:
    					cout<<50<<endl;
    					break;
    				default:
    					if(IsFirstHalf(strs[count[i]], counts[count[i]], strs[0][i]))
    					{
    						cout<<55 + 10 * count[i]<<endl;
    					}
    					else
    					{
    						cout<<50 + 10 * count[i]<<endl;
    					}
    					break;
    			}
    		}
    		cout<<endl;
    	}
        return 0;
    }
    

      

  • 相关阅读:
    获取DataGrid数据
    C# 分頁
    TCP 协议
    node fs对象
    ANSI转义码 改变输出的字体颜色
    异步流程控制模式
    node event对象
    js中的异常捕获 try{} catch{}(二)
    node require 文件查找的顺序
    node process全局对象
  • 原文地址:https://www.cnblogs.com/forcheng/p/7634892.html
Copyright © 2011-2022 走看看