当前位置:网站首页>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 」)
边栏推荐
- Pic16f877xa instruction system (assembly language)
- Easy to use code statistics tool
- EXCEL
- error: redefinition of
- %d,%s,%c,%x
- Simple factory factory method Abstract Factory
- 【obs】视频包发送的dts_usec 计算
- Play with the one-stop plan of cann target detection and recognition [basic]
- [Yugong series] July 2022 go teaching course 016 logical operators and other operators of operators
- How can dbcontext support the migration of different databases in efcore advanced SaaS system
猜你喜欢
![[sword finger offer] analog implementation ATOI](/img/01/76a3b1fcc6403368a363146d553777.png)
[sword finger offer] analog implementation ATOI

Leetcode sword finger offer brush question notes
Shell script realizes the scheduled backup of MySQL database on two computers

Software engineering in Code: regular expression ten step clearance

Observer mode

Insight into mobile application operation growth in 2022 white paper: the way to "break the situation" in the era of diminishing traffic dividends

Developers must read: 2022 mobile application operation growth insight white paper

JZ7 rebuild binary tree

Rongyun launched a real-time community solution and launched "advanced players" for vertical interest social networking

LeetCode46全排列(回溯入门)
随机推荐
Basic usage of thread class
What are the hazards of insufficient sleep?
Ida Pro novice tutorial
Leetcode 115. different subsequences
C control open source library: download of metroframework
[jailhouse article] base architectures for virtual physical computing (2018)
常吃发酵馒头是否会伤害身体
Qt实战案例(53)——利用QDrag实现拖拽拼图功能
C#控件开源库:MetroFramework的下载
Can communication test based on STM32: turn the globe
Detailed explanation of the difference, working principle and basic structure between NMOS and PMOS
[add, delete, modify, and check the array base]
JZ7 rebuild binary tree
MySQL remote login
Introduction to bridging mode and sharing mode
CRC8 CRC16 table lookup method
代码中的软件工程:正则表达式十步通关
Easy to use code statistics tool
Example demonstration of math.random() random function
Rongyun launched a real-time community solution and launched "advanced players" for vertical interest social networking