文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>ACM竞赛做题的输入输出惯用伎俩(1)

ACM竞赛做题的输入输出惯用伎俩(1)

时间:2010-12-15  来源:jinhaoxia

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 50) which is the number of test cases. And it will be followed by T consecutive test cases.

意思是要有首先输入一个T,然后输入T行测试样本。我们以
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2970
为例子。为了保留这些测试样本,有那门一种做法:

#include <iostream>
#include <string.h>

main()
{
        using namespace std;
        
        int times;
        cin>>times;
        
        while(times--)
        {
                char type[10];
                int      many;
                
                int get;
                int most;
                
                cin>>type;
                cin>>many;
                
                if(strcmp(type,"Faster")==0)
                {
                        most=0x7fffffff;
                        
                        while(many--)
                        {
                                cin>>get;
                                if(get<most)
                                {
                                        most=get;
                                }
                        }
                }
                else
                {
                        most=0;
                        
                        while(many--)
                        {
                                cin>>get;
                                if(get>most)
                                {
                                        most=get;
                                }
                        }
                }
                
                cout<<most<<endl;
        }
}

对于这种题目都有一个固定框架,那就是:

#include <iostream>
#include <string.h>

main()
{
        using namespace std;
        
        int times;
        cin>>times;
        
        while(times--)
        {
                //什么测试实例
                //输入测试实例
          
                //处理
          
                //输出
        }
}

要理解这种写法,要首先理解C的文件机制,显示器和键盘对C来说不过就是文件,用户端的输入输出或许交错在一起,其实他们都在他们的缓冲区中单独存在。

相关阅读 更多 +
排行榜 更多 +
野生恐龙射击生存安卓版

野生恐龙射击生存安卓版

飞行射击 下载
无尽的三月七h5

无尽的三月七h5

休闲益智 下载
枪火小队战场生存安卓版

枪火小队战场生存安卓版

飞行射击 下载