题目链接:http://acm.hdu.edu.cn/diy/contest_show.php?cid=27435
密码:jxnuacs
如果你之前没刷过题,不知道如何读取多组数据,那么可以看下这篇文章,传送门开启~ ACM基本输入输出
然后就是代码提交的问题,C++的代码用GNU C++或者Microsoft visual C++提交,C语言代码用 GNU C提交 。
下面是这次热身赛的题解:
第一题,输入10个数,要求输出其中的最大值。
题目很简单,无论用什么方法,相信大家都能写得出来,关键的问题是可能不知道如何读取多组数据。
那么还是再建议看下前面给出的ACM基本输入输出的链接。
有了上面文章的基础,应该就写的来了。
下面是C++版的AC代码:
由于C++中有求数组最大值的函数,比较方便,可以直接调用
#include<iostream>//输入输出流cin cout的头文件
#include<algorithm>//max_element函数用到的头文件
#include<cstdlib>
#include<cstdio>
using namespace std;
int main()
{
int a[11];
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
while(cin>>a[0])//多组输入,当读完测试文件时,程序就会结束
{
for(int i=1;i<10;i++) cin>>a[i];//读入剩余的九个数
cout<<*max_element(a,a+10)<<endl;//直接调用取这十个数中的最大值的函数
}
return 0;
}
那么相比较而言,C语言就显得很原始了,什么基本函数都要自己去实现。
下面是C语言的AC代码:
#include<stdio.h>
int main()
{
int a[11],Max,i;
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
while(~scanf("%d",&a[0]))//多组输入,当读完测试文件时,程序就会结束
{
for(i=1;i<10;i++) scanf("%d",&a[i]);//读入剩余的九个数
Max=a[0];
for(i=1;i<10;i++)
if(Max<a[i]) Max=a[i];
printf("%d\n",Max);
}
return 0;
}
字符串反转也很简单,直接调用函数即可。
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
string s;
//freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
while(getline(cin,s))//整行读取字符串,一直到不能读数据为止
{
reverse(s.begin(),s.end());//调用反转的函数
cout<<s<<endl;
}
return 0;
}
排序也是很简单,直接调用函数。
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
const int maxn=100005;//定义整型常量maxn=100005
int a[maxn];//当要开比较大的数组时,就要定义成全局变量,防止爆系统栈
int main()
{
int n;
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(~scanf("%d",&n))//数据量大的数据用scanf读比较快
{
for(int i=0;i<n;i++) scanf("%d",&a[i]);
sort(a,a+n);//排序
for(int i=0;i<n;i++) printf("%d ",a[i]);
printf("\n");
}
return 0;
}
总之,这些题很简单,只是让你们熟悉环境用的。防止你们在比赛的时候出现一系列问题。