Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <cstdio>
- #include <string>
- using namespace std;
- int main() {
- char answ;
- string temp;
- string name1, name2;
- do {
- int count_fin = 0;
- int file1_arr[256] = { 0 };
- int file2_arr[256] = { 0 };
- cout << "Input a filename of 1st file>";
- ifstream file1;
- getline(cin, name1);
- file1.open(name1+".txt");
- while (!file1.is_open()) {
- cout << "Can't open your file\n";
- cout << "Input a filename of 1st file>";
- getline(cin, name1);
- file1.open(name1+".txt");
- }
- while (!file1.eof()) {
- getline(file1,temp);
- for(int g = 0; g < temp.length(); g ++){
- file1_arr[(int)temp[g]] += 1;
- }
- temp.clear();
- }
- file1.close();
- cout << "Input a filename of 2nd file>";
- ifstream file2;
- getline(cin, name2);
- file2.open(name2 + ".txt");
- while (!file2.is_open()) {
- cout << "Can't open your file\n";
- cout << "Input a filename of 2st file>";
- getline(cin, name2);
- file2.open(name2 + ".txt");
- }
- while (!file2.eof()) {
- getline(file2, temp);
- for (int g = 0; g < temp.length(); g++) {
- file2_arr[(int)temp[g]] += 1;
- }
- temp.clear();
- }
- file2.close();
- name1.clear();
- name2.clear();
- for (int i = 0; i < 255; i++) {
- if (file1_arr[i] == file2_arr[i]) {
- count_fin += 1;
- }
- }
- /*cout << count_fin << endl;
- for (int i = 0; i < 255; i++) {
- cout << file1_arr[i];
- }
- cout << endl;
- for (int i = 0; i < 255; i++) {
- cout << file2_arr[i];
- }*/
- if (count_fin == 255) {
- cout << "\nIt's possible to rearrange characters in the first file to get the second file";
- }
- else {
- cout << "\nIt's impossible to rearrange characters in the first file to get the second file";
- }
- cout << "\nContinue? (Y/N)>";
- cin >> answ;
- while (cin.fail() || cin.peek() != '\n' || (answ!='y' && answ != 'Y' && answ != 'n' && answ != 'N')) {
- cin.clear();
- cin.ignore(10000, '\n');
- cout << "\nContinue? (Y/N)>";
- cin >> answ;
- }
- cin.ignore(10000, '\n');
- } while (answ == 'y' || answ == 'Y');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment