skupi967 Temat założony przez niniejszego użytkownika |
» 2020-06-14 13:13:47 Nie bede zakladal nowego tematu co by juz tak nie spamowac wiec napisze tutaj. Moj program po napotkaniu przecinka usuwa to co jest po nim bo tak ma byc ale po 4 przecinku jest liczba i chcialbym sortowac wyniki wlasnie na podstawie tej liczby za 4 przecinkiem od najwiekszej do najmniejszej. Da sie to jakos zgrabnie zrobic? phrase, jewish gematria, english gematria, simple gematria, search num elvis presly, 1479, 972, 162, 52 the young ones, 995, 1008, 168, 6 hassanyahu talks about psychopathic toys on austins birfday, 3967, 3948, 658, 0 anu to arrive by jewish gematria word jewish gematria english is wine he is unforgivable because i dont have to do they trembled and kissed his mission markbot, 11993, 8988, 1498, 82 tak wyglada plik words.txt i interesuja mnie indeksy sortowania po 4 przecinku. Jakis pomysl sensei @pekfos? Tutaj source code #include <iostream> #include <string> #include <map> #include <cmath> #include <fstream> #include <sstream> #include <numeric> #include <limits>
using namespace std;
void print( string::size_type n, string const & s ) { if( n == string::npos ) { cout << "not found\n"; } else { cout << "found: " << s.substr( n ) << '\n'; } }
map < char, int > make_pythagorean_map() { return { { 'A', 1 }, { 'a', 1 }, { 'B', 2 }, { 'b', 2 }, { 'C', 3 }, { 'c', 3 }, { 'D', 4 }, { 'd', 4 }, { 'E', 5 }, { 'e', 5 }, { 'F', 6 }, { 'f', 6 }, { 'G', 7 }, { 'g', 7 }, { 'H', 8 }, { 'h', 8 }, { 'I', 9 }, { 'i', 9 }, { 'J', 1 }, { 'j', 1 }, { 'K', 2 }, { 'k', 2 }, { 'L', 3 }, { 'l', 3 }, { 'M', 4 }, { 'm', 4 }, { 'N', 5 }, { 'n', 5 }, { 'O', 6 }, { 'o', 6 }, { 'P', 7 }, { 'p', 7 }, { 'Q', 8 }, { 'q', 8 }, { 'R', 9 }, { 'r', 9 }, { 'S', 1 }, { 's', 1 }, { 'T', 2 }, { 't', 2 }, { 'U', 3 }, { 'u', 3 }, { 'V', 4 }, { 'v', 4 }, { 'W', 5 }, { 'w', 5 }, { 'X', 6 }, { 'x', 6 }, { 'Y', 7 }, { 'y', 7 }, { 'Z', 8 }, { 'z', 8 } }; }
map < char, int > make_simpleeng_map() { return { { 'A', 1 }, { 'a', 1 }, { 'B', 2 }, { 'b', 2 }, { 'C', 3 }, { 'c', 3 }, { 'D', 4 }, { 'd', 4 }, { 'E', 5 }, { 'e', 5 }, { 'F', 6 }, { 'f', 6 }, { 'G', 7 }, { 'g', 7 }, { 'H', 8 }, { 'h', 8 }, { 'I', 9 }, { 'i', 9 }, { 'J', 10 }, { 'j', 10 }, { 'K', 11 }, { 'k', 11 }, { 'L', 12 }, { 'l', 12 }, { 'M', 13 }, { 'm', 13 }, { 'N', 14 }, { 'n', 14 }, { 'O', 15 }, { 'o', 15 }, { 'P', 16 }, { 'p', 16 }, { 'Q', 17 }, { 'q', 17 }, { 'R', 18 }, { 'r', 18 }, { 'S', 19 }, { 's', 19 }, { 'T', 20 }, { 't', 20 }, { 'U', 21 }, { 'u', 21 }, { 'V', 22 }, { 'v', 22 }, { 'W', 23 }, { 'w', 23 }, { 'X', 24 }, { 'x', 24 }, { 'Y', 25 }, { 'y', 25 }, { 'Z', 26 }, { 'z', 26 } }; }
map < char, int > make_gfive_map() { return { { 'A', 7 }, { 'a', 7 }, { 'B', 8 }, { 'b', 8 }, { 'C', 1 }, { 'c', 1 }, { 'D', 2 }, { 'd', 2 }, { 'E', 3 }, { 'e', 3 }, { 'F', 4 }, { 'f', 4 }, { 'G', 5 }, { 'g', 5 }, { 'H', 6 }, { 'h', 6 }, { 'I', 7 }, { 'i', 7 }, { 'J', 8 }, { 'j', 8 }, { 'K', 9 }, { 'k', 9 }, { 'L', 1 }, { 'l', 1 }, { 'M', 2 }, { 'm', 2 }, { 'N', 3 }, { 'n', 3 }, { 'O', 4 }, { 'o', 4 }, { 'P', 5 }, { 'p', 5 }, { 'Q', 6 }, { 'q', 6 }, { 'R', 7 }, { 'r', 7 }, { 'S', 8 }, { 's', 8 }, { 'T', 9 }, { 't', 9 }, { 'U', 1 }, { 'u', 1 }, { 'V', 2 }, { 'v', 2 }, { 'W', 3 }, { 'w', 3 }, { 'X', 4 }, { 'x', 4 }, { 'Y', 5 }, { 'y', 5 }, { 'Z', 6 }, { 'z', 6 } }; }
map < char, int > select_map( int choice ) { switch( choice ) { case 1: { return make_pythagorean_map(); } case 2: { return make_simpleeng_map(); } case 3: { return make_gfive_map(); } } }
int main() { int cho = 0, d; char o; string phrasetwo; while( 1 ) { system( "cls" ); cout << "You want to use: " << endl << "1) Pythagorean Gematria" << endl << "2) English/Simple Gematria" << endl << "3) Extra: " << endl << "Gematria with G = 7" << endl << endl; cin >> phrasetwo; istringstream asd( phrasetwo ); if( !( asd >> d ) || asd >> o ) { system( "cls" ); cout << "You want to use: " << endl << "1) Pythagorean Gematria" << endl << "2) English/Simple Gematria" << endl << "3) Extra: " << endl << "Gematria with G = 7" << endl << endl; } else { cho = stoi( phrasetwo ); if( cho <= 3 && cho >= 1 ) { break; } } } auto m = select_map( cho ); string::size_type n; ifstream input( "words.txt" ); ofstream output( "results.txt" ); string str, phrase; int counter = 1, cnt = 0, choice = 0, chosennum = 0, asd = 0, f = 0, x; bool flag; char c; while( 1 ) { system( "cls" ); cout << "You want to check:" << '\n' << "1) Number" << '\n' << "2) Phrase" << endl; cin >> phrase; istringstream s( phrase ); if( !( s >> x ) || s >> c ) { system( "cls" ); cout << "You want to check:" << '\n' << "1) Number" << '\n' << "2) Phrase" << endl; } else { choice = stoi( phrase ); if( choice <= 2 && choice >= 1 ) { break; } } } switch( choice ) { case 1: { cout << "Which number do you want to check?: "; while( 1 ) { cin >> phrase; istringstream s( phrase ); if( !( s >> x ) || s >> c ) { cout << endl << "Which number do you want to check?: "; } else { chosennum = stoi( phrase ); break; } } cout << endl << "All words found: " << endl; break; } case 2: { do { flag = false; cout << "Which phrase do you want to check?: "; cin.ignore( numeric_limits < streamsize >::max(), '\n' ); getline( cin, phrase ); for( int i = 0; i < phrase.length(); i++ ) { if( isdigit( phrase[ i ] ) ) { flag = true; } } cout << endl; } while( flag == true ); for( char charr: phrase ) { chosennum += m[ charr ]; } cout << '\t' << phrase << " in gematria = " << chosennum << endl << endl << "All words found: " << endl; break; } } output << "All words found: " << endl; while( getline( input, str ) ) { int sum = 0; n = str.find( ',' ); if( n != string::npos ) { str.resize( n ); } for( int i = 0; i < str.length(); i++ ) { if((( int ) str[ i ] ) > 127 ||(( int ) str[ i ] ) < 0 ) { str.clear(); } } for( char charr: str ) { sum += m[ charr ]; } if( sum == chosennum ) { cout << "No[" << counter << "]: " << str << "(" << sum << ")" << '\n'; output << "No[" << counter << "]: " << '\t' << str << " = " << sum << endl; counter++; } } cout << "\n\n You have found: " << counter << " words" << '\n'; output << "\n\n You have found: " << counter << " words" << '\n'; return 0; }
|