For a while, there was a cry for help on the Internet, asking how to break this. In fact, this code is very simple, the index array is the subscript of the arr array, index[0]=2 corresponds to arr[2]=1, index[1]=0 corresponds to arr[0]=8, index[2]=3 Corresponding to arr[3]=0, and so on... It is easy to get the phone number 18013820100.
This question asks you to write a program that generates this code for any phone number -- in fact, just generate the first two lines, and the rest will be unchanged.
Input format:
Enter an 11-digit mobile number given in one line.
Output format:
Generate the first two lines of code for the entered number, where the numbers in arr must be given in descending order.
Input sample:18013820100Sample 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};
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int main(){ int t,a[10],b[10]; char str[15]; gets(str); memset(a,-1,sizeof(a)); for(int i=0;str[i]!='\0';i++){ t=str[i]-'0'; a[t]=t; } cout<<"int[] arr = new int[]{"; int j=0,flag1=0; for(int i=9;i>=0;i--){ if(flag1&&(a[i]>=0)) cout<<","; if(a[i]>=0){ cout<<a[i]; flag1 = 1; b[a[i]]=j++; } } cout<<"};"<<endl; cout<<"int[] index = new int[]{"; int flag2=0; for(int i=0;str[i]!='\0';i++){ if(flag2) cout<<","; cout<<b[str[i]-'0']; flag2=1; } cout<<"};"<<endl; return 0; }