当前位置:网站首页>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]);
}边栏推荐
- 分布式事务(Seata) 四大模式详解
- tonybot 人形机器人 首次开机 0630
- 7-23 currency conversion (using array conversion)
- 别再问自己适不适合做软件测试了
- Mongodb index
- Happy capital new dual currency fund nearly 4billion yuan completed its first account closing
- Luogu p5536 [xr-3] core city solution
- 超简单手机地图开发
- Accelerating strategy learning using parallel differentiable simulation
- 必贝特医药冲刺科创板:年营收97万亏损1.37亿 拟募资20亿
猜你喜欢

牛客网:过河卒

NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon

Tonybot humanoid robot checks the port and corresponds to port 0701

Tailing rushes to the scientific and Technological Innovation Board: it plans to raise 1.3 billion, and Xiaomi Changjiang is the shareholder

Understand the application scenario and implementation mechanism of differential segment

tonybot 人形机器人 红外遥控玩法 0630
![洛谷P5018 [NOIP2018 普及组] 对称二叉树 题解](/img/89/da1a3a38e02671628f385de0f30369.png)
洛谷P5018 [NOIP2018 普及组] 对称二叉树 题解

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

亚马逊、速卖通、Lazada、Shopee、eBay、wish、沃尔玛、阿里国际、美客多等跨境电商平台,测评自养号该如何利用产品上新期抓住流量?

NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
随机推荐
Etcd cluster permission management and account password usage
npm install卡住与node-npy的各种奇怪报错
ConstraintLayout 的使用
Pyqt interface production (login + jump page)
Sendmail无法发送邮件及发送过慢解决
中国PETG市场预测及战略研究报告(2022版)
分布式事务(Seata) 四大模式详解
关于敏捷的一些概念
Zhonggan micro sprint technology innovation board: annual revenue of 240million, net loss of 17.82 million, proposed to raise 600million
7-4 BCD decryption (10 points)
Puzzle (016.4) domino effect
etcd集群权限管理和账号密码使用
Sub-GHz无线解决方案Z-Wave 800 系列ZG23 soc和ZGM230S模块
Special research report on the market of lithium battery electrolyte industry in China (2022 Edition)
分布式事务(Seata) 四大模式详解
Jiuyi cloud black free encryption free version source code
Common shortcut keys in PCB
7-6 mixed type data format input
Strategy, tactics (and OKR)
愉悦资本新双币基金近40亿元完成首次关账