2844. 排序去重

#include <stdio.h>
#include <stdlib.h>

int main()
{
char sort;
int nums[1001];
int i = 0;
for(i = 0; i <= 1000 ; ++i)
nums[i] = 0;
while((scanf("%c", &sort)) != EOF){
while((scanf("%d" , &i)) != EOF){
nums[i]++;
}
}
if(sort == 'A'){
for(i = 0; i <= 1000 ; ++i)
if(nums[i] > 0)
printf("%d ", i);
}
else{
for(i = 1000; i > 0 ; --i)
if(nums[i] > 0)
printf("%d ", i);
}
printf("\n");
}


#include
using namespace std;

int main() {
int temp;
char c;
set<int> s;
cin >> c;
while (cin >> temp)
s.insert(temp);
auto i1 = s.begin();
auto i2 = s.rbegin();
if (c == 'A'){
cout << *(i1++);
while (i1 != s.end())
cout << ' ' << *(i1++);
}
else {
cout << *(i2++);
while (i2 != s.rend())
cout << ' ' << *(i2++);
}
return 0;
}


“换行符”有什么玄机

CR LF？？？？？
[em:05][em:05]

include

using namespace std;
int main()
{
set st;
char ch = getchar();
int num;
while (cin >> num)
{
st.insert(num);
}
if (ch == ‘D’)
{
set::iterator it = st.end();
for (it–; it != st.begin(); it–)
{
cout << it << ” “;
}
cout <<
it–;
}
else
{
for (set::iterator it = st.begin(); it != st.end(); it++)
{
cout << *it << ” “;
}
}
cout << endl;
return 0;
}

2844

#include <algorithm>
#include <cstdio>
#include <functional>
#include <vector>
using namespace std;
int main() {
char way;
scanf("%c", &way);
vector<unsigned> nums;
for (int temp; scanf("%u", &temp) != EOF; nums.push_back(temp))
;
if (way == 'A')
sort(nums.begin(), nums.end());
else
sort(nums.rbegin(), nums.rend());
auto ed = unique(nums.begin(), nums.end());
printf("%u", nums.front());
for (auto i = nums.begin() + 1; i != ed; ++i)
printf(" %u", *i);
}