Problem description
Each number in the statistics of n positive integers, the number of occurrences of the
The input description
The first line is an integer n (5 & lt; N<30), said he calculated integer number of the second line is n integers, each integer is less than 100000
The output shows that
In accordance with the order of the integer since the childhood, in turn, the output of different integers and their occurrences, between integer and occurrences with a colon (:) to separate,
CodePudding user response:
Will sort, written after the sorting first, then the output, and then adjust the output format, the code on the first take a look
CodePudding user response:
struct number { Int val. int time;//the number of }; Can consider to use structure, code recommended himself to write
CodePudding user response:
reference 2 building self-confidence boy reply: struct number { Int val. int time;//the number of }; Can consider to use structure, code recommended himself to write Time is not suitable for variable name It has been a standard library functions are the name Although used here will not go wrong CodePudding user response:
#include using namespace std; Int getin (); The class test { int num; Int * date; Public: The test () : num (0), date (NULL) {} The test (int n, int da []); Void stor (); //friend ostream & amp; Operator<(ostream & amp; OS, const test & amp; St); Void tj () const; Void getn (); To test () {delete [] date; }; }; The test: test (int n, int da []) { Num=n; The date=da; } Void test: : getn () { Do { Num=getin (); If (num & lt; =1)Cout & lt; <"Integer number is too little, re-enter \ n"; } while (num & lt;=1); The date=new int (num); For (int I=0; I & lt; Num. I++) The date [I]=getin (); } Void test: : stor () { For (int I=0; I & lt; Num. I++) Cout & lt; <"" & lt; Int tema, temb, tem; For (int I=0, j=num - 1; I & lt; J; I++, j -) { For (int f=I; f { If (date [I] & gt; The date [f]) { Tema=date [I]; The date [I]=date [f]; The date [f]=tema; } If (date [j] { Temb=date [j]; The date [j]=date [f]; The date [f]=temb; } } } Cout & lt; <"Stor" & lt; For (int I=0; I & lt; Num. I++) Cout & lt; <"" & lt; Cout & lt; } Void test: : tj (const) { Int I, flag, tem, n=0; For (I=0; I & lt; Num. I++) { N=0; Flag=0; Tem=date [I]; For (int k=0; K & lt; i; K++) If (tem==date [k])//to determine whether a statistical first few statistical {flag=1; break; }//statistics into the next cycle If (flag==1) continue; For (int j=I; J & lt; Num. J++) If (tem==date [j]) n++;//statistical number Cout & lt; } } Int getin () { Int temp=0; Cin & gt;> Temp. if (! Cin) { Cout & lt; <"Input error! \n"; Cin. The clear (); Cin. Ignore (1024), '\ n'); Getin (); } Else if (temp & gt; 100000) { Cout & lt; <"Please enter an integer less than 100000 \ n"; Cin. Ignore (1024), '\ n'); } The else return temp; } Int main () { The test ts; Ts. Getn (); Ts. Stor (); Ts. Tj (); return 0; } Try this for a moment, just began to learn, learn skills not jing, bosses, please give directions CodePudding user response:
reference lin5161678 reply: 3/f Quote: refer to the second floor confident boy reply: struct number { Int val. int time;//the number of }; Can consider to use structure, code recommended himself to write Time is not suitable for variable name It has been a standard library functions are the name Although used here will not go wrong That's changed, no problem, solve the compile error is the most basic ~ CodePudding user response:
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html