当前位置:网站首页>7-3 rental (20 points)
7-3 rental (20 points)
2022-07-03 14:33:00 【Study hard 867】
At one time, the Internet was full of cries for help , How to break this . In fact, this code is very simple ,index
Array is arr
Index of the array ,index[0]=2
Corresponding arr[2]=1
,index[1]=0
Corresponding arr[0]=8
,index[2]=3
Corresponding arr[3]=0
, And so on …… It's easy to get a phone number 18013820100
.
This question asks you to write a program , Generate this code for any phone number —— in fact , Just generate the first two lines , The rest is the same .
Input format :
Type in a line to give a result of 11 A cell phone number made up of digits .
Output format :
Generate the first two lines of code for the entered number , among arr
The numbers in must be given in descending order .
sample input :
18013820100
sample output :
int[] arr = new int[]{8,3,2,1,0};
int[] index = new int[]{3,0,4,3,1,0,2,4,3,4,4};
Ideas : First of all, we have to take out all the numbers in the mobile phone number , Then we need to sort the mobile phone numbers , Then we will correspond to the mobile phone number from arr You can make corresponding inside .
Sorting is used here , We have to create a new array to store our original array , Let the new array sort , The ordered numbers are in the same block , So we can use a[i]==a[i-1] To determine whether it is a new number , Here we need an array to store non duplicate data , Then compare the size of non duplicate data , Finally, match it with the mobile phone number .
Code :
#include <stdio.h>
#include <string.h>
int main(){
char a[12],y[12];
gets(a);
strcpy(y,a);// Because you need to change the order of the original array , So we need to assign a value to the original array .
printf("int[] arr = new int[]{");
int i,j;
static int b[10];
char max,n=1,u,v=0;
int s,temp=0;
s=strlen(a);
for(i=0;i<strlen(a);i++){
max=a[i];
for(j=i+1;j<strlen(a);j++){// Sort the array
if(max<a[j]){
a[i]=a[j];
a[j]=max;
max=a[i];
}
}
}
int e[10];
e[0]=a[0]-'0';
v=1;
for(i=1;i<s;i++){// Remove duplicate numbers
if(a[i]!=a[i-1]){
e[v++]=a[i]-'0';
n++;
}
}
for(i=0;i<n;i++){// Sort the array without duplicate numbers
temp=e[i];
for(j=i+1;j<n;j++){
if(temp<e[j]){
e[i]=e[j];
e[j]=temp;
temp=e[i];
}
}
}
for(i=0;i<n-1;i++)printf("%d,",e[i]);
printf("%d",e[n-1]);
printf("};\n");
printf("int[] index = new int[]{");
int arr[11];
for(i=0;i<s;i++){// Sort the corresponding mobile phone number .
for(j=0;j<n;j++){
if(e[j]==y[i]-'0'){arr[i]=j;
break;
}
}
}
for(i=0;i<s-1;i++){
printf("%d,",arr[i]);
}
printf("%d};",arr[s-1]);
}
边栏推荐
- tonybot 人形機器人 紅外遙控玩法 0630
- Accelerating strategy learning using parallel differentiable simulation
- 如何查询淘宝天猫的宝贝类目
- NPM install is stuck with various strange errors of node NPY
- npm install卡住与node-npy的各种奇怪报错
- 基因家族特征分析 - 染色体定位分析
- Common shortcut keys in PCB
- Use of constraintlayout
- 必贝特医药冲刺科创板:年营收97万亏损1.37亿 拟募资20亿
- Leetcode (4) -- find the median of two positively ordered arrays
猜你喜欢
Eight sorts
分布式事务(Seata) 四大模式详解
556. 下一个更大元素 III
US stock listing of polar: how can the delivery of 55000 units support the valuation of more than 20billion US dollars
Luogu p5018 [noip2018 popularization group] symmetric binary tree problem solution
论文分享:Generating Playful Palettes from Images
Showmebug entered Tencent conference, opening the era of professional technical interview
7-15 calculation of PI
retrofit
Four data flows and cases of grpc
随机推荐
7-2 and then what time (15 minutes)
基因家族特征分析 - 染色体定位分析
Tailing rushes to the scientific and Technological Innovation Board: it plans to raise 1.3 billion, and Xiaomi Changjiang is the shareholder
【7.3】146. LRU caching mechanism
String reverse order
6-9 statistics of single digits (15 points)
Similarities and differences between Allegro, OrCAD, net alias, port, off page connector and how to select them
Timecho of Tianmou technology completed an angel round financing of nearly 100 million yuan to create a native timing database of the industrial Internet of things
Polestar美股上市:5.5万台交付如何支持得起超200亿美元估值
tonybot 人形机器人 查看端口并对应端口 0701
Niuke: crossing the river
洛谷P5018 [NOIP2018 普及组] 对称二叉树 题解
【北大青鸟昌平校区】互联网行业中,哪些岗位越老越吃香?
tonybot 人形機器人 紅外遙控玩法 0630
使用并行可微模拟加速策略学习
Bibit pharmaceutical rushed to the scientific innovation board: annual revenue of 970000, loss of 137million, proposed to raise 2billion
J-luggage lock of ICPC Shenyang station in 2021 regional games (simple code)
Convert string to decimal integer
Sword finger offer 28 Symmetric binary tree
天谋科技 Timecho 完成近亿元人民币天使轮融资,打造工业物联网原生时序数据库