L1-027
来源:互联网 发布:最优化方法应用例题 编辑:程序博客网 时间:2024/06/06 00:54
一时间网上一片求救声,急问这个怎么破。其实这段代码很简单,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 <string>#include <set>#include <array>#include <algorithm>using namespace std;int main(){ set<int>s; string num; int a[11]; int flag = 0; cin >> num; for (int i = 0; i < 11; i++) s.insert(num[i]-'0'); //for (auto i=s.rbegin();i!=s.rend();i++) //cout << *i; cout << "int[] arr = new int[]{"; for (auto i = s.rbegin(); i != s.rend(); i++) { a[*i] =flag ; flag++; if (i == s.rbegin())cout << *i; else cout <<','<< *i; } cout << "};" << endl; cout << "int[] index = new int[]{"; for (int i = 0; i < 11; i++) { if (i == 0)cout << a[num[i]-'0']; else cout << ',' << a[num[i]-'0']; } cout << "};"; system("pause");}
知识点,rebegin and rend,it’s still from rebegin to the rend,but you should make it ++ and it will form the end to the begin;
阅读全文
0 0
- L1-027
- 团体程序设计天梯赛L1-027 出租
- L1-graph
- cocos2d L1
- 笔记---L1
- L1范数
- swift L1
- L1-011
- L1-006
- L1-009
- L1-023
- L1-001
- PAT L1
- PAT L1
- L1-017
- L1-005
- L1-007
- L1-011
- Struts2笔记04 action获取表单数据
- Zoj 3829 Known Notation
- 使用IntelliJ IDEA 配置Maven(入门)
- 微信支付退款接口
- python3/tensorflow1.2
- L1-027
- 面试题14—调整数组顺序使奇数位于偶数前面
- HTTPS抓包分析
- 5种方法解除开机密码
- 《Spring AOP入门——动态代理》
- jsp中自定义tag标签
- 'GridSearchCV' object has no attribute 'cv_results_' 这一问题的解决
- 四、单例模式
- 串口通信校验方式(even,odd,space,mark)UART数据波形分析