Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- #include <utility>
- #include <algorithm>
- bool isDigitOrX(char s, std::string &digitsOrXs, std::string & otherChars){
- if (!(isdigit(s)||s=='X')){
- digitsOrXs.push_back(' ');
- otherChars.push_back(s);
- return false;
- }
- digitsOrXs.push_back(s);
- return true;
- }
- int formatNumbers(std::string in = "input.txt", std::string out="output.txt"){
- std::ifstream infile(in);
- std::ofstream outfile(out);
- std::string line;
- if (!infile.is_open()) {
- std::cerr<<"file can't open\n";
- }
- std::getline(infile, line);
- std::cout<<"l:"<<line<<"\n";
- int N = std::stoi(line);
- std::vector<std::string> numbers(N);
- std::cout<<"mllmlm\n";
- for (int i=0; i<N; i++){
- std::getline(infile, line);
- std::cout<<"number"<<i<<" "<<line<<"\n";
- line.erase(remove_if(line.begin(), line.end(), [](char c) { return !isdigit(c); } ), line.end());
- numbers.push_back(line);
- }
- std::cout<<"l:"<<line<<"\n";
- std::getline(infile, line);
- N = std::stoi(line);
- std::vector<std::pair<std::string, std::string>> patterns(N);
- for (int i=0; i<N; i++){
- std::getline(infile, line);
- std::string otherChars, digitsOrXs;
- line.erase(remove_if(line.begin(), line.end(), [](char c) { return !/*isDigitOrX(c,digitsOrXs,otherChars)*/isdigit(c); } ), line.end());
- patterns.push_back(std::make_pair(digitsOrXs, otherChars));
- }
- for (auto const number:numbers){
- int maxConcordance = 0;
- int indexMaxConcordancePattern = -1;
- int concordance=0;
- for(int i=0; i<patterns.size(); i++){
- auto const pattern = patterns[i];
- concordance=0;
- bool cont = true;
- for(int j = 0; j<pattern.first.size()&&cont; j++){
- auto const charFromPattern = pattern.first[j];
- for(int h= 0; h<number.size()&&cont; h++){
- auto const charFromNumber = number[h];
- if (charFromPattern!=' '){
- if(charFromPattern == 'X'){
- concordance++;
- }
- else if(charFromPattern == charFromNumber){
- concordance++;
- }
- else{
- cont=false;
- }
- }
- }
- }
- std::cout<<" "<<patterns[indexMaxConcordancePattern].first;
- if(concordance>maxConcordance){
- maxConcordance = concordance;
- indexMaxConcordancePattern = i;
- }
- }
- auto dOrX = patterns[indexMaxConcordancePattern].first;
- auto othersIt = patterns[indexMaxConcordancePattern].second.begin();
- auto numbIt = number.begin();
- std::string result;
- for (auto const s:dOrX){
- if (s==' '){
- result.push_back(/**(othersIt++)*/'j');
- }
- else {
- result.push_back(/**(numbIt++)*/'k');
- }
- }
- outfile<<result<<"\n";
- }
- }
- int main(int argc, char *argv[])
- {
- formatNumbers("D:\\QtCreatorSources\\build-phoneNumbers-Desktop_Qt_5_7_0_MinGW_32bit-Debug\\debug\\input.txt", "D:\\QtCreatorSources\\build-phoneNumbers-Desktop_Qt_5_7_0_MinGW_32bit-Debug\\debug\\output.txt");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement