当前位置:网站首页>Electronic Association C language level 2 60, integer parity sort (real question in June 2021)
Electronic Association C language level 2 60, integer parity sort (real question in June 2021)
2022-07-25 06:55:00 【dllglvzhenfeng】
/*
Electronics Association C Language 2 level 60 、 Integer parity sorting (2021 year 6 The real question of the month )
Given 10 A sequence of integers , Ask to reorder it . Sorting requirements :
1. Odd number first , Even numbers come after ;
2. Odd numbers are sorted in descending order ;
3. Even numbers are sorted in reverse order of input .
Input : The input line , contain 10 It's an integer , Separate each other with a space ,
The range of each integer is greater than or equal to 0,
Less than or equal to 100.
Output : After sorting as required, a row containing sorted 10 It's an integer ,
Numbers are separated by a space .
The sample input
4 7 3 13 11 12 0 47 34 98
Sample output
47 13 11 7 3 98 34 0 12 4
*/
#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int a[10+10],b[10+10];
int m=0,n=0,temp,i;
for(i=1; i<=10; i++)
{
cin>>temp;
if(temp%2==1)
{
a[m]=temp;
m++;
}
else
{
b[n]=temp;n++;
}
}
sort(a,a+m,cmp); // Array elements are sorted from large to small
for(i=0; i<m; i++)
cout<<a[i]<<" ";
for(i=0; i<n; i++)
cout<<b[n-1-i]<<" "; // Sort in reverse order according to the input order Reverse output
return 0;
}
/*
Homework :
1.10 Simple sorting of programming basics 06 Integer parity sorting
http://noi.openjudge.cn/ch0110/06/
http://bailian.openjudge.cn/practice/3682/
http://bailian.openjudge.cn/practice/2871/
*/1.10 Simple sorting of programming basics 06 Integer parity sorting
OpenJudge - 06: Integer parity sorting
OpenJudge - 3682: Integer parity sorting
C++ Code : Method 1
/*
1.10 Simple sorting of programming basics 06 Integer parity sorting Method 1
http://noi.openjudge.cn/ch0110/06/
http://bailian.openjudge.cn/practice/3682/
http://bailian.openjudge.cn/practice/2871/
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a[100], b[100];
for (int i = 0; i < 10; i++)
{
cin >> a[i];
}
int cnt=0;
for(int i=0;i<10;i++){
if(a[i]%2==1)
{
b[cnt]=a[i];
cnt++;
}
}
sort(b,b+cnt,greater<int>());
int temp=cnt;
for(int i=0;i<10;i++)
{
if(a[i]%2==0)
{
b[cnt]=a[i];
cnt++;
}
}
sort(b+temp,b+10);
for (int i = 0; i < 10; i++)
{
cout << b[i] << " ";
}
cout << endl;
return 0;
}C++ Code : Method 2
/*
1.10 Simple sorting of programming basics _06 Integer parity sorting Method 2
http://noi.openjudge.cn/ch0110/06/
Total time limit : 1000ms Memory limit : 65536kB
describe
Given 10 A sequence of integers , Ask to reorder it . Sorting requirements :
1. Odd number first , Even numbers come after ;
2. Odd numbers are sorted in descending order ;
3. Even numbers are sorted in descending order .
Input
The input line , contain 10 It's an integer , Separate each other with a space , The range of each integer is greater than or equal to 0, Less than or equal to 100.
Output
Sort as required and output a line , Include sorted 10 It's an integer , Numbers are separated by a space .
The sample input
4 7 3 13 11 12 0 47 34 98
Sample output
47 13 11 7 3 0 4 12 34 98
source
1873
*/
#include <iostream>
#include <cstdio>
using namespace std;
int a[105];
int b[105];
int main()
{
int c,i,j=0,k=0;
for(int i=0; i<10; i++)
{
cin >> c;
if(c%2==1)
a[j++]=c;
else
b[k++]=c;
}
for(int i=0; i<j; i++)
{
for(int l=0; l<j-1-i; l++)
{
if(a[l]<a[l+1])
{
swap(a[l],a[l+1]);
}
}
}
for(int i=0; i<k; i++)
{
for(int l=0; l<k-1-i; l++)
{
if(b[l]>b[l+1])
{
swap(b[l],b[l+1]);
}
}
}
for(int i=0; i<j; i++)
{
cout << a[i] << " ";
}
for(int i=0; i<k; i++)
{
cout << b[i] << " ";
}
return 0;
} python3 Code :
"""
1.10 Simple sorting of programming basics 06 Integer parity sorting
http://noi.openjudge.cn/ch0110/06/
"""
a=list(map(int,input().split()))
lena=len(a)
ans01=[]
ans02=[]
i=0
while i<lena:
if a[i]%2==0:
ans01.extend([int(a[i])])
else:
ans02.extend([int(a[i])])
i+=1
ans01.sort()
ans02.sort()
#print(ans01)
#print(ans02)
j=len(ans02)-1
while j>=0:
print("%d" %ans02[j],end=" ")
j-=1
k=0
while k<len(ans01):
print("%d" %ans01[k],end=" ")
k+=1About the choice of programming language for children ,python still c++
2022 Summer vacation and 9 month CSP-J1 CSP-S1 Preliminaries Training plan and learning points
Scratch -> C++ drawing -> Xinao (C++) Learn navigation
Scratch -> C++ drawing -> Xinao (C++) Learn navigation _dllglvzhenfeng The blog of -CSDN Blog
Blue Bridge Cup Youth creative programming contest scratch Group 、 China Electronics Society scratch Grade examination, etc
from Scratch To C++ from Scratch To python Books
from Scratch To C++ from Scratch To python Books _dllglvzhenfeng The blog of -CSDN Blog
C++ Game introduction book recommendation
Simple programming competition notes ( draft )
Primary school C++ Introduction to programming books and related materials ( One )
Primary school C++ Introduction to programming books and related materials ( Two ) Algorithm
Primary school C++ Introduction to programming ( 3、 ... and )
Children programming :C++ Drawing related books
from Scratch To C++ from Scratch To python Books
from Scratch To C++ from Scratch To python Books _dllglvzhenfeng The blog of -CSDN Blog
Animation learning Xinao Comic algorithms CSP-J beginner ( One )、 Computer foundation and programming environment ( basis 「NOI The outline 」)
Animation learning Xinao Comic algorithms CSP-J beginner ( Two )、C++ Programming data structure ( basis 「NOI The outline 」)
Animation learning Xinao Comic algorithms CSP-J beginner ( 3、 ... and )、 Algorithm ( basis 「NOI The outline 」)
边栏推荐
- DOM event type
- 【每日一题】1184. 公交站间的距离
- R strange grammar summary
- Download and run the C open source control metroframework demo project
- Qt实战案例(53)——利用QDrag实现拖拽拼图功能
- DOM events
- Software engineering in Code: regular expression ten step clearance
- Ida Pro novice tutorial
- Shell run command
- Leetcode sword finger offer brush question notes
猜你喜欢

在C# WinForms应用程序中安装,配置和使用MetroFramework

JS array = number assignment changes by one, causing the problem of changing the original array

A little consideration of strategic mode

QT actual combat case (53) -- using qdrag to realize the drag puzzle function

Not only log collection, but also the installation, configuration and use of project monitoring tool sentry

Can communication test based on STM32: turn the globe

Install, configure, and use the metroframework in the C WinForms application
Shell script realizes the scheduled backup of MySQL database on two computers

Software engineering in Code: regular expression ten step clearance

Quick sort code implementation
随机推荐
Octopus network community call 1 starts Octopus Dao construction
CodeForces 1417B Two Arrays
流量对于元宇宙来讲并不是最重要的,能否真正给传统的生活方式和生产方式带来改变,才是最重要的
Standard C language 6
Restrict Su command and sudo mechanism to promote nmap and console command netstat
Builder pattern
Cointelegraph撰文:依托最大的DAO USDD成为最可靠的稳定币
如何学习 C 语言?
LeetCode46全排列(回溯入门)
代码中的软件工程:正则表达式十步通关
Thread 类的基本用法
Shell run command
【transformer】DeiT
【愚公系列】2022年7月 Go教学课程 015-运算符之赋值运算符和关系运算符
Upload and download multiple files using web APIs
【C】 Program environment and pretreatment
RecycleView实现item重叠水平滑动
【愚公系列】2022年7月 Go教学课程 016-运算符之逻辑运算符和其他运算符
js数据类型的判断——案例6精致而优雅的判断数据类型
Easy to use code statistics tool