There are two arrays - the first is the representation of the date of birth (DD.MM.YYYY) as a set of numbers, the elements of the second array are obtained by some transformations over the date of birth (such as adding the digits of the day and month, then the year, etc.).

Example of the first array: {2,2,0,1,1,9,9,3}

Example of the second array: {3,7,6,7,5}

It is necessary to register in the matrix of the form: exactly as many digits i are recorded in the element i as many as they occur in the above arrays.

1 4 7 2 5 8 3 6 9 

(the account goes vertically) and in the final work

 11 - 77 22 5 - 33 6 99 

type insert numbers into the matrix (don’t know how to insert) if someone doesn’t understand the task, google the Pythagorean square

this is what is available at the moment:

 #include <iostream> using namespace std; int main() { const int indate = 8, dvozn=1; int date[indate], numb[dvozn], sum = 0, sum2 = 0, sum3 = 0; cout << "Vvedit' datu narodzhenia v cyfrah(1 9 9 0 1 1 2 9" << endl; for (int i = 0; i < indate; i++) { cin >> date[i]; //1 number sum += date[i]; } numb[0] = sum; //2 number while (sum > 9) { sum = ((sum / 10) + (sum % 10)); } //3 number int tmp = 0; cout << date[0] << " " << date[1] << " " << ((date[0] * 10) + (date[1])) * 2 << endl; tmp += ((date[0] * 10) + (date[1]))*2; sum2 = numb[0] - tmp; if (sum2 < 0) sum2 *= -1; sum3 = sum2; while (sum3 > 9) { sum3 = ((sum3 / 10) + (sum3 % 10)); } cout << endl << sum << " " << sum2 << " " << sum3 << endl; //zapovnennia tablyci for (int i = 0; i < indate; i++) { cout << date[i]; } cout << endl; const int size5 = 5; int dat[size5]; dat[0] = numb[0]/10; dat[1] = numb[0]%10; dat[2] = sum; dat[3] = sum2; dat[4] = sum3; for (int i = 0; i < size5; i++) { cout << dat[i] << "-"; } cout << endl; const int size = 3; int arr[size][size]; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { } } } 

help please, well don `t know how to fill it and that's it. I'm already thinking about the day

  • And what should each element of the matrix be? For example, 11 is an array of two units or the number 11? - yrHeTaTeJlb
  • @yrHeTaTeJlb is the number of the first two arrays. If there were 4 units in these two arrays, 4 units would be there, not 11, but 1111. something like that)) is it difficult to explain)) or explain? - tkachuk
  • 1111 is int i = 1111; or std::vector<int> v = {1, 1, 1, 1}; ? - yrHeTaTeJlb
  • @yrHeTaTeJlb here: "In its form, this will be a table with a size of 3x3 cells, into which numbers from 1 to 9 should be placed. numbers 1, 2, 3 top to bottom, in the second - 4, 5, 6 also from top to bottom, in the third - 7, 8, 9. There should not be zeros in the table, so they just need to be missed. - tkachuk
  • @yrHeTaTeJlb So, now in the organization data you need to insert all the numbers that are located in the two rows found - the date of birth and the calculated elements. All units must be entered in the first cell, all twos in the second (as described above, it is the second in the first column) and so on, up to nine. If there are no definite numbers in the previously compiled series, the cell simply remains empty, you can write the word “no.” " - tkachuk

2 answers 2

I recommend first to form the result as an array, and then convert it into a matrix. This is easiest to do using std::valarray .

 #include <iostream> #include <vector> #include <valarray> template<class Iterator> void fill(Iterator begin, Iterator end, std::valarray<int> &result){ for(;begin != end; ++begin){ result[*begin] = result[*begin] * 10 + *begin; } } int main(){ //Исходные данные std::vector<int> v1 = {2, 2, 0, 1, 1, 9, 9, 3}; std::vector<int> v2 = {3, 7, 6, 7, 5}; //Результат ввиде массива std::valarray<int> result(10); //Формируем массив fill(v1.begin(), v1.end(), result); fill(v2.begin(), v2.end(), result); //Преобразуем массив в матрицу std::valarray<std::valarray<int>> matrix(std::valarray<int>(3), 3); for(int i = 0; i < 3; ++i){ std::slice slice(i + 1, 3, 3); matrix[i] = result[slice]; } //Вывод матрицы на экран for(const std::valarray<int> &line : matrix){ for(int i : line){ std::cout << i << " "; } std::cout << std::endl; } } 

http://cpp.sh/6pwt

UPD Option without using the standard library, functions, templates and everything else

 #include <iostream> #include <iomanip> int main(){ //Исходные данные int v1[] = {2, 2, 0, 1, 1, 9, 9, 3}; int v2[] = {3, 7, 6, 7, 5}; //Результат ввиде массива int result[10] = {0}; //Формируем массив for(unsigned int i = 0; i < sizeof(v1)/sizeof(int); ++i){ int number = v1[i]; result[number] = result[number] * 10 + number; } for(unsigned int i = 0; i < sizeof(v2)/sizeof(int); ++i){ int number = v2[i]; result[number] = result[number] * 10 + number; } //Преобразуем массив в матрицу int matrix[3][3]; for(int i = 0; i < 3; ++i){ for(int j = 0; j < 3; ++j){ matrix[i][j] = result[i + 1 + 3 * j]; } } //Печатаем матрицу std::cout << std::setw(2); for(int i = 0; i < 3; ++i){ for(int j = 0; j < 3; ++j){ int number = matrix[i][j]; if(number > 0){ std::cout << number << " "; } else{ std::cout << "- "; } } std::cout << std::endl; } } 
  • no functions needed ( - tkachuk
  • Apparently, and without templates, especially, yes? - isnullxbh
  • @tkachuk, well, paste the function code instead of calling - yrHeTaTeJlb
  • @isnullxbh I do not understand what you mean, but probably yes - tkachuk
  • @yrHeTaTeJlb and without a vector - tkachuk
 #include <iostream> #include <string> #include <ctype.h> int main() { const int resLength = 9; const int numLength = 8; // это для массива 2 - я взял 5 просто так, сами определите const int appLength = 5; int resArr[resLength] = { 0 }; int numArr[numLength] = { 0 }; // ПОВТОРЯЮ - второй массив проинициализировал сам // Вы же сделаете нужные вам расчеты, и получите элементы для него const int appArr[appLength] = { 2,2,4,5,5 }; std::string birthDateAsStr; std::cout << "\nВведите дату Вашего рождения: "; std::cin >> birthDateAsStr; // из строки в массив int count = 0; const char * ptr = birthDateAsStr.c_str(); for (int i = 0; i < birthDateAsStr.size(); ++i) { if (isdigit(birthDateAsStr[i])) { // не красиво, но работает ( const char c = birthDateAsStr[i]; numArr[count++] = atoi(&c); } } // вывожу в линейный, но соответствие "цифре I ячейка I" - сохраняется. // для 1 for (int i = 0; i < numLength; ++i) { if (numArr[i] == 0) continue; resArr[numArr[i] - 1] *= 10; resArr[numArr[i] - 1] += numArr[i]; } // для 2 for (int i = 0; i < appLength; ++i) { if (numArr[i] == 0) continue; resArr[appArr[i] - 1] *= 10; resArr[appArr[i] - 1] += appArr[i]; } // а вот вывожу уже как 1 4 7 // 2 5 8 // 3 6 9 for (int i = 0; i < 3; ++i) { std::cout << resArr[i] << " " << resArr[i + 3] << " " << resArr[i + 6] << std::endl; } std::system("pause"); return 0; }