1 #include <iostream>
2 #include "stdlib.h"
3 using namespace std;
4
5 void Show()
6 {
7 cout<<"CIS 25 – C++ Programming \n";
8 cout<<"Laney College \n";
9 cout<<"Your Name \n\n";
10 cout<<"Assignment Information -- \n";
11 cout<<" Assignment Number: Lab 03, \n";
12 cout<<" Coding Assignment -- Exercise #1 \n";
13 cout<<" Written by: Your Name \n";
14 cout<<" Submitted Date: Due Date \n";
15 }
16
17
18 void Calculate()
19 {
20 int size;
21 int tmp;
22 int i,j,k;
23
24 cout << "\nHow many intergers? ";
25 cin >> size;
26
27 int *ptrPtr = new int[20];
28
29 for (i = 0; i < size; i++) {
30
31 cout << "Enter integer #"<< i + 1 << ": ";
32 cin >> tmp;
33
34 *(ptrPtr + i) = tmp;
35 }
36
37 cout<<"\nThe original array:\n";
38 for (j = 0; j < size; j++)
39 cout << " " << *(ptrPtr + j)<<"\n";
40 cout<<"\nCalling extractUncommonDigitYourName() –\n\n";
41 cout<<"Displaying after returning the array -- The uncommon digits:\n";
42
43
44 // cout<<size<<endl;
45 char **Total_data =NULL;
46 Total_data = new char*[size];
47 int* num = new int[10];//every data digital
48 for (i = 0; i < size; i++) {
49 *(Total_data + i) = new char[10];
50 if(*(ptrPtr + i)<0)*(ptrPtr + i) = -(*(ptrPtr + i));//取相反数
51 _itoa(*(ptrPtr + i), *(Total_data + i), 10);
52 //cout<<*(ptrPtr + i)<<endl;
53 j = 0;
54 for(;*(*(Total_data+i)+j)!='\0';j++){}
55 *(num+i) = j;
56 // for(j=0;j<*(num+i);j++)cout<<*(*(Total_data+i)+j)<<" ";
57 // cout<<endl;
58 }
59 // for(i=0;i<size;i++)cout<<*(num+i)<<endl<<endl;
60
61 char *total_num = new char[100];
62 int number = 0;
63 bool flags = false;
64 for(i=0;i<size;i++)
65 {
66 for(j=0;j<*(num+i);j++)
67 {
68 flags = true;
69 for(k=0;k<number;k++)
70 {
71 if(*(total_num+k)==*(*(Total_data+i)+j))
72 {
73 flags = false;
74 break;
75 }
76 }
77 if(flags)
78 {
79 *(total_num+number) = *(*(Total_data+i)+j);
80 number++;
81 }
82 }
83 }
84 // for(i=0;i<number;i++)cout<<*(total_num+i)<<" ";
85 // cout<<endl;
86
87 char *last_data = new char[100];
88 int last_number = 0;
89 int count = 0;//某个数字在几组数据出现的次数
90 for(i=0;i<number;i++)
91 {
92 count = 0;
93 for(j=0;j<size;j++)
94 {
95 for(k=0;k<*(num+j);k++)
96 {
97 if(*(*(Total_data+j)+k)==*(total_num+i))
98 {
99 count++;
100 break;
101 }
102 }
103 }
104 if(count==1)//某个数字只在这几组数据中一组数据出现
105 {
106 *(last_data+last_number) = *(total_num+i);
107 last_number++;
108 }
109 }
110
111 // for(i=0;i<last_number;i++)cout<<*(last_data+i)<<" ";
112 // cout<<endl;
113 if(last_number==0){
114 cout<<" There is/are no uncommon digit(s)\n"<<endl;
115 }else{
116 //希尔排序算法
117 int dh,temp;
118 dh=last_number/2;
119 while(dh>=1){
120 for( i=dh;i<last_number;i++){
121 temp=*(last_data+i);
122 j=i-dh;
123 while(j>=0&&*(last_data+j)>temp){
124 *(last_data+j+dh)=*(last_data+j);
125 j-=dh;
126 }
127 *(last_data+j+dh)=temp;
128 }
129 dh/=2;
130 }
131 // for(i=0;i<last_number;i++)cout<<*(last_data+i)<<" ";
132 // cout<<endl;
133 cout<<" There is/are "<<last_number<<" uncommon digit(s)\n";
134 for(i=0;i<last_number;i++)//输出偶数
135 {
136 if(*(last_data+i)%2==0)cout<<" "<<*(last_data+i)<<endl;
137 }
138 for(i=0;i<last_number;i++)//输出奇数
139 {
140 if(*(last_data+i)%2!=0)cout<<" "<<*(last_data+i)<<endl;
141 }
142 cout<<endl;
143 }
144
145 }
146
147
148 int main()
149 {
150 Show();
151 int option;
152 //bool flags = true;
153 while(1)
154 {
155 // flags = false;
156 cout<<"*********************************************\n";
157 cout<<"* MENU * \n";
158 cout<<"* 1. Calling extractUncommonDigitYourName() * \n";
159 cout<<"* 2. Quit * \n";
160 cout<<"********************************************* \n";
161 cout<<"Select an option (1 or 2):";
162 cin>>option;
163 if(option!=2&&option!=1)
164 {
165 cout<<"\n WRONG OPTION!\n\n";
166 }else {
167 switch(option)
168 {
169 case 1:
170 Calculate();
171 break;
172 case 2:
173 cout<<"\n Fun Exercise ..."<<endl;
174 exit(0);
175 break;
176 }
177 }
178 }
179 return 0;
180 }