当前位置:网站首页>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]);
}边栏推荐
- Convert string to decimal integer
- 7-2 and then what time (15 minutes)
- Leetcode (4) -- find the median of two positively ordered arrays
- Analysis of gene family characteristics - chromosome location analysis
- MongoDB索引
- tonybot 人形机器人 首次开机 0630
- Too many files with unapproved license
- tonybot 人形机器人 红外遥控玩法 0630
- 分布式事务(Seata) 四大模式详解
- [clean up the extraordinary image of Disk C]
猜你喜欢

一文了解微分段应用场景与实现机制

提高效率 Or 增加成本,开发人员应如何理解结对编程?
![洛谷P4047 [JSOI2010]部落划分 题解](/img/7f/3fab3e94abef3da1f5652db35361df.png)
洛谷P4047 [JSOI2010]部落划分 题解

Analysis of gene family characteristics - chromosome location analysis

Comprehensive evaluation of good-looking, easy-to-use and powerful handwriting note taking software: notability, goodnotes, marginnote, handwriting, notes writers, collanote, collanote, prodrafts, not

Tonybot Humanoïde Robot Infrared Remote play 0630

x86汇编语言-从实模式到保护模式 笔记

Puzzle (016.3) is inextricably linked

tonybot 人形機器人 紅外遙控玩法 0630

tonybot 人形机器人 红外遥控玩法 0630
随机推荐
Output student grades
7-18 finding the single root of polynomial by dichotomy
Add ZABBIX calculation type itemcalculated items
Exercise 6-6 use a function to output an integer in reverse order
Solr series of full-text search engines - basic principles of full-text search
ShowMeBug入驻腾讯会议,开启专业级技术面试时代
C library function - qsort()
Mongodb index
China PETG market forecast and Strategic Research Report (2022 Edition)
Thread. Sleep and timeunit SECONDS. The difference between sleep
Exercise 10-3 recursive implementation of exponential functions
Analysis of gene family characteristics - chromosome location analysis
7-2 and then what time (15 minutes)
tonybot 人形机器人 首次开机 0630
天图投资冲刺港股:资产管理规模249亿 投了小红书与奈雪
How to query the baby category of tmall on Taobao
JVM garbage collector
Luogu p5018 [noip2018 popularization group] symmetric binary tree problem solution
tonybot 人形机器人 定距移动 代码编写玩法
7-6 mixed type data format input