Untitled

 avatar
unknown
plain_text
4 years ago
1.9 kB
6
Indexable
#include <iostream>
#include <fstream>
using namespace std;

///Program
//
//int main() {
//    int a,b;
//    read(a);
//    read(b);
//    while(a!=b)
//    {
//        if(a > b) {
//            a = a - b;
//        };
//        if(b >= a) {
//            b = b - a;
//        };
//    };
//    print(a);
//}
//

void atomSearch(const char *fileName, const char *outputFileName) {
    ifstream f(fileName);
    string line, element, output;

    while (getline(f, line)) {
        for (int i = 0; i < line.length(); i++)
        {
            // check for variable names / definded words etc
            if(isalnum(line[i]) || (line[i] == '.' && isdigit(line[i-1]) && isdigit(line[i+1]))) {
                element += line[i];
            } else {
                if (!element.empty()) {
                    output = output + element + "\n";
                    element = "";
                }

                //check for special signs like ,;{}()
                if(strchr(".,;{}()",line[i])) {
                    output = output + line[i] + "\n";
                }

                // check for + - *
                else if(strchr("+-*",line[i])) {
                    output = output +  line[i] + "\n";
                }

                // check for <= >=  == !=
                else if((line[i] == '<' && line[i+1] == '=') || (line[i] == '>' && line[i+1] == '=') || (line[i] == '=' && line[i+1] == '=') || (line[i] == '!' && line[i+1] == '=')) {
                    output = output + line[i] + line[i+1] + "\n";
                    i++;
                }

                // check for < > =
                else if(strchr("<>=",line[i])) {
                    output = output + line[i] + "\n";
                }
            }
        }
    }

    // Write to output file
    ofstream g(outputFileName);
    g << output;
}


int main() {
    atomSearch("g++.in","g++.out");
    return 0;
}
Editor is loading...