格式数字九度OJ 1185 特殊排序
每日一贴,今天的内容关键字为格式数字
标题链接:http://ac.jobdu.com/problem.php?pid=1185
标题分析:
简略的数字排序。
要注意输出的格式,我就因为格式的问题涌现了一次Presentation Error。还要注意标题的理解,它说的很不清楚,就是当存在几个一样的数字同时都是最大数的话,只剔除1个就可以,全剔除会WA。
源代码:
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int num;
while (cin>>num)
{
int a[1050] = {0};
int temp;
int max; //保存最大数
if (num >= 1 && num <= 1000)
{
for (int i = 0; i < num; i++)
{
cin>>a[i];
}
for (int i = 0; i < num; i++)
{
for (int j = i + 1; j < num; j++)
{
if (a[i] > a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
if (num == 1)
{
cout<<a[0]<<endl;
cout<<"-1"<<endl;
}
else
{
max = a[num - 1];
cout<<max<<endl;
for (int i = 0; i < num - 1; i++)
{
if (i == num - 2)
{
cout<<a[i]<<endl;
}
else
cout<<a[i]<<" ";
}
}
}
}
return 0;
}
文章结束给大家分享下程序员的一些笑话语录: 某程序员对书法十分感兴趣,退休后决定在这方面有所建树。花重金购买了上等的文房四宝。一日突生雅兴,一番磨墨拟纸,并点上了上好的檀香,颇有王羲之风 范,又具颜真卿气势,定神片刻,泼墨挥毫,郑重地写下一行字:hello world.

浙公网安备 33010602011771号