当前位置:网站首页>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]);
}边栏推荐
- Ultra simple mobile map development
- 全文检索引擎Solr系列—–全文检索基本原理
- Niuke: crossing the river
- protobuf与grpc
- 天图投资冲刺港股:资产管理规模249亿 投了小红书与奈雪
- Tonybot humanoid robot checks the port and corresponds to port 0701
- GRPC的四种数据流以及案例
- Preliminary summary of structure
- 7-24 reduction of the simplest fraction (rolling Division)
- SSH访问控制,多次失败登录即封掉IP,防止暴力破解
猜你喜欢

MySQL multi table query subquery

Tonybot humanoid robot checks the port and corresponds to port 0701

Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions

Happy capital new dual currency fund nearly 4billion yuan completed its first account closing

Why is this error reported when modifying records in the database

分布式事务(Seata) 四大模式详解

Creation of data table of Doris' learning notes

Sub GHz wireless solution Z-Wave 800 Series zg23 SOC and zgm230s modules

Mysql多表查询 #子查询

puzzle(016.3)千丝万缕
随机推荐
Luogu p5194 [usaco05dec]scales s solution
String substitution
NPM install is stuck with various strange errors of node NPY
适用于XP的DDK
Exercise 8-8 moving letters
7-14 sum integer segments (C language)
亚马逊、速卖通、Lazada、Shopee、eBay、wish、沃尔玛、阿里国际、美客多等跨境电商平台,测评自养号该如何利用产品上新期抓住流量?
Some concepts about agile
Facebook 如何将 Instagram 从 AWS 搬到自己的服务器
Get permissions dynamically
Showmebug entered Tencent conference, opening the era of professional technical interview
Eight sorts
提高效率 Or 增加成本,开发人员应如何理解结对编程?
npm install卡住与node-npy的各种奇怪报错
How to query the baby category of tmall on Taobao
7-23 currency conversion (using array conversion)
7-28 monkeys choose King (Joseph problem)
必贝特医药冲刺科创板:年营收97万亏损1.37亿 拟募资20亿
556. The next larger element III
Puzzle (016.3) is inextricably linked