Untitled
user_9831585
plain_text
2 years ago
4.6 kB
5
Indexable
#include <iostream> #include <fstream> int* words(char* str , int* psize); void initialization(); int ress(float* arr1 , float* arr2 , int size); void initialization1(); void initialization2(); int main() { initialization2(); //initialization1(); //initialization(); // char str[80]; // std::cout<<"Enter your string -> "<<std::endl; // std::cin.getline(str, 80); // // int size = 0; // int* indices = words(str, &size); // // std::cout<<"The size of arr is -> "<<size<<std::endl; // for (int i = 0; i < size; i++) { // std::cout<<"Index of word " << i + 1 << ": " << indices[i] <<std::endl; // } // // delete[] indices; // return 0; } int* words(char* str , int* psize) { int counter = 0; int* index = 0; bool prev_is_space = true; for (int i = 0; i < strlen(str); i++) { if (str[i] == ' ') { prev_is_space = true; } else { if (prev_is_space) { prev_is_space = false; ++counter; if (index == 0) { index = new int[counter]; } else { int* temp = new int[counter]; for (int i = 0; i < counter - 1; i++) { temp[i] = index[i]; } delete[] index; index = temp; } index[counter - 1] = i; } } } *psize = counter; return index; } void initialization() { float* arr1 = 0; float* arr2 = 0; int size = 0; std::cout<<"Enter size for Input number to arr1 and arr2 -> "<<std::endl; std::cin>>size; arr1 = new float[size]; std::cout<<"Enter your numbers for arr1 -> "<<std::endl; for (int i = 0; i < size; ++i) { std::cin>>arr1[i]; } arr2 = new float[size]; std::cout<<"Enter your numbers for arr2 -> "<<std::endl; for (int j = 0; j < size; ++j) { std::cin>>arr2[j]; } int flag = ress(arr1 + 1, arr2 + 1, size - 1); if (flag == 1) { std::cout<<"The arrays meet the demand -> "<<flag<<std::endl; } else std::cout<<"The arrays meet the not demand -> "<<flag<<std::endl; delete[] arr1; delete[] arr2; } int ress(float* arr1 , float* arr2 , int size) { if (size == 0) { return 0; } if (size == 1) { if ((arr1[0] * 10) == arr2[0]) { return 1; } else return 0; } return ress(arr1 + 1, arr2 + 1,size - 1); } void initialization1() { float min_row = 0; float min_col = 0; float max_row = 0; float max_col = 0; float sum = 0; float matrix[4][4]; std::cout<<"Enter your numbers for arr -> "<<std::endl; for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { std::cin>>matrix[i][j]; sum += matrix[i][j]; } max_row = sum; min_row = sum; sum = 0; } for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { sum += matrix[i][j]; } if ( min_row > sum) { min_row = sum ; } if (max_row < sum) { max_row = sum; } sum = 0; } for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { sum += matrix[j][i]; } max_col = sum; min_col = sum; sum = 0; } for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { sum += matrix[j][i]; } if ( min_col > sum) { min_col = sum ; } if (max_col < sum) { max_col = sum; } sum = 0; } std::cout<<min_row<<std::endl; std::cout<<max_row<<std::endl; std::cout<<min_col<<std::endl; std::cout<<max_col<<std::endl; } void initialization2() { std::fstream f ; int arr=0; f.open("/Users/lidor123/Desktop/avarega1", std::ios::in); if (!f) { std::cout<<"Error -> Try Agiain"<<std::endl; return; } //int i = 0; while (!f.eof()) { f>>arr; } std::cout<<arr<<std::endl; f.close(); }
Editor is loading...