L1-027. 出租
来源:互联网 发布:python开发exe程序 编辑:程序博客网 时间:2024/05/07 12:45
下面是新浪微博上曾经很火的一张图:
一时间网上一片求救声,急问这个怎么破。其实这段代码很简单,index数组就是arr数组的下标,index[0]=2 对应 arr[2]=1,index[1]=0 对应 arr[0]=8,index[2]=3 对应 arr[3]=0,以此类推…… 很容易得到电话号码是18013820100。
本题要求你编写一个程序,为任何一个电话号码生成这段代码 —— 事实上,只要生成最前面两行就可以了,后面内容是不变的。
输入格式:
输入在一行中给出一个由11位数字组成的手机号码。
输出格式:
为输入的号码生成代码的前两行,其中arr中的数字必须按递减顺序给出。
输入样例:18013820100输出样例:
int[] arr = new int[]{8,3,2,1,0};int[] index = new int[]{3,0,4,3,1,0,2,4,3,4,4};实在是不会做这题,每次碰见就绕里面,找了个代码,先保留着,有时间再研究研究
#include <iostream>#include <algorithm>#include <string>#include <stdio.h>#include <string.h>#include <math.h>#include <vector>#define ll long longusing namespace std;int main(){ string str; while (cin >> str) { int number[15] = {0}; for (int i = 0; i < str.length(); i ++) number[str[i] - '0'] ++; cout << "int[] arr = new int[]{"; vector<int> v; // 输出arr 数组中一共出现了哪几个数 for (int i = 9; i >= 0; i --) if (number[i] != 0) { if (!v.empty()) cout << ","; cout << i; v.push_back(i); } cout << "};" << endl; cout << "int[] index = new int[]{"; int num = v.size(); for(int i = 0; i < str.length(); i ++) for(int j = 0; j < num; j ++) if (str[i] - '0' == v[j]) { if (i != 0) cout << ","; cout << j; break; } cout << "};" << endl; } return 0;}
0 0
- L1-027. 出租
- L1-027. 出租
- L1-027. 出租
- L1-027. 出租
- L1-027. 出租
- L1-027. 出租
- PAT L1-027. 出租
- L1-027. 出租
- L1-027. 出租
- L1-027. 出租
- PAT-L1-027. 出租
- L1-027. 出租 java
- L1-027. 出租
- L1-027. 出租
- L1-027. 出租
- PAT-L1-027. 出租
- pat:L1-027. 出租
- L1-027. 出租
- ThreadLocal 内部实现和应用场景
- 泛域名Wildcard Domain
- 理解“类对象”的用意
- Unity 内存管理
- recommandation of sohu
- L1-027. 出租
- [福利] 绝对良心 Smart C++(Dev C++ 6.00)
- 索引
- 高效的for循环
- Java面试题全集(7)
- php 四种基础排序算法
- Pycharm的git/github配置及其问题解决
- pring mvc中的@RequestMapping的用法。
- C++异常处理