int letterCount(int number) { if ((number >= 0) && (number <= 9)) switch(number) { case 0: return 0; case 1: return 3; // one case 2: return 3; // two case 3: return 5; // three case 4: return 4; // four case 5: return 4; // five case 6: return 3; // six case 7: return 5; // seven case 8: return 5; // eight case 9: return 4; // four } if ((number >= 10) && (number <= 19)) switch(number) { case 10: return 3; // ten case 11: return 6; // eleven case 12: return 6; // twelve case 13: return 8; // thirteen case 14: return 8; // fourteen case 15: return 7; // fifteen case 16: return 7; // sixteen case 17: return 9; // seventeen case 18: return 8; // eighteen case 19: return 8; // nineteen } if ((number >= 20) && (number <= 99)) switch ((number % 100) / 10) { case 2: return 6 + letterCount(number % 10); // twenty- case 3: return 6 + letterCount(number % 10); // thirty- case 4: return 5 + letterCount(number % 10); // forty- case 5: return 5 + letterCount(number % 10); // fifty- case 6: return 5 + letterCount(number % 10); // sixty- case 7: return 7 + letterCount(number % 10); // seventy- case 8: return 6 + letterCount(number % 10); // eighty- case 9: return 6 + letterCount(number % 10); // ninety- } if ((number >= 100) && (number <= 999)) { int value = 7; // hundred value += letterCount((number % 1000) / 100); // one hundred if ((number % 100) != 0) value += 3 + letterCount(number % 100); // one hundred and thirty seven return value; } if (number == 1000) return 3 + 8; // one thousand printf("FAIL with number %d\n", number); exit(1); }
GBitmap* GFont::drawOCRBaseImage(uint startRec,uint rowsNum){ string str; int w=63; int h=63; if(startRec==0)startRec++; GBitmap *tableImg=GBitmap::create(w*20,h*20+20); //находим нужную букву по idNumber int step=0,y=0; //TIME_START //cout<<"@@@letterCount="<<letterCount()<<" rowsNum="<<rowsNum<<endl; for(int i=startRec;i<startRec+rowsNum&&i<letterCount();i++){ GLetter *letter=getLetter(i); //cout_<<"aliKali[0]["<<i<<"]->name="<<letter->name<<" OCRKey="<<letter->OCRKey<<endl; if(letter->name=="*"){letter->destroy();continue;} GBitmap *letterImg=letter->drawLetterPict(1); //GBitmap *letterImg=letter->mask128.unPackMask(); GBitmap *letterImgScale=GBitmap::createScale(letterImg,0.3); tableImg->drawImg(letterImgScale,w*step+17,y+15); step++; if(step==20){ //tableImg->drawImg(blank,w*step-40,y-90); y+=h;step=0; } letterImg->destroy(); letterImgScale->destroy(); } return tableImg; }
int main(int argc, char **argv) { unsigned int value; unsigned int sum = 0; test(); for (int i = 1; i <= 1000; i++) { value = letterCount(i); sum += value; printf("%d -> %d\n", i, value); } printf("%d\n", sum); }
int main(void) { int i; //index int *frequency, *letCat, *letLength; int puzzNum, maxLength, catNum; int roundNum=5; //number of rounds. 5 by default int opt=1; //loop variable, initially yes; FILE* in; in=fopen("puzz.list", "r"); fscanf(in, "%d %d %d", &puzzNum, &maxLength, &catNum); puzzle* list = readPuzzles(in, puzzNum); frequency = letterCount(list, puzzNum); letCat = malloc(catNum*sizeof(int)); for(i=0; i<catNum; i++) { //by default, all categories are included, letCat[i]=1; //so we initialize allowCat to all 1's. } letLength = malloc( (maxLength+1)*sizeof(int) ); for(i=0; i<=maxLength; i++) { //by default, all lengths are included, letLength[i]=1; //so we intialize allowLength to all 1's } /* while (opt) { printf("1 Play a game\n2 Adjust settings\n3 Bonus options\n\n"); scanf("%d", &opt); if (opt == 1){ printf("broken\n\n"); } else if(opt == 2) { settings(); } else if(opt == 3) { printf("broken\n\n"); } else if(opt) { printf("nice try, but never(probably)\n\n"); } }*/ return 0; }
void GFont::drawOCRBasePict(uint startRec,uint rowsNum, int mode){ cout_<<"draw table mode="<<mode<<endl; string str; int w=63; int h=63; int letterPageCount=2000; if(mode)letterPageCount=20000; if(startRec==0)startRec++; GBitmap *tableImg=GBitmap::create(w*20,h*20+20); //cout_<<"w="<<tableImg->columns()<<" h="<<tableImg->rows()<<endl; //GBitmap *blank=GBitmap::create(w*5+40,h+120); //int in=-1; //cout_<<"input id="<<idNumber<<" correctionTable.size()="<<correctionTable.size()<<endl; //находим нужную букву по idNumber int step=0,y=0; //TIME_START cout_<<"@@@letterCount="<<letterCount(); for(int i=startRec;i<startRec+rowsNum;i++){ GLetter *letter=getLetter(i); //cout_<<"aliKali[0]["<<i<<"]->name="<<letter->name<<" OCRKey="<<letter->OCRKey<<endl; if(letter->name=="*"){letter->destroy();continue;} GBitmap *letterImg=letter->drawLetterPict(1); //GBitmap *letterImg=letter->mask128.unPackMask(); GBitmap *letterImgScale=GBitmap::createScale(letterImg,0.3); tableImg->drawImg(letterImgScale,w*step+17,y+15); step++; if(step==20){ //tableImg->drawImg(blank,w*step-40,y-90); y+=h;step=0; } letterImg->destroy(); letterImgScale->destroy(); } //TIME_PRINT_ string path=inputData.data["root"]+"edit/OCRBase.jpg"; ((GImageEditor*)inputData.imageEditor)->WriteImageData(tableImg,path,0); tableImg->destroy(); }
/********************************************* ** Function: main ** Description: reads in input string, outputs number of words in string and number of occurrences of each letter ** Parameters: none ** Pre-Conditions: none ** Post-Conditions: return 0 ********************************************/ int main() { int letters[numLetters]; // initializes array that counts letters char input[size]; // initializes array storing input string // reads input string std::cout << "Input string: " << std::endl; std::cin.getline(input, size); std::cout << input << std::endl; letterCount(input, letters); std::cout << std::endl; // prints number of words in input string std::cout << "You have " << wordCount(input) << " words with these letters:" << std::endl; // lists occurrences of each letter for (int i = 0; i < numLetters; i++) { if (letters[i] > 0) { std::cout << static_cast<char>(i+'a') << " " << letters[i] << std::endl; } } return 0; }
int main() { int counter = 0, orig_words_len = 0, i; char orig_words[LEXICON_LEN][MAX_STR]; // Initialize orig_words for (counter=0;counter<LEXICON_LEN;counter++) orig_words[counter][0] = '\0'; puts(" GET WORDS "); getWordList(orig_words); puts(" GOT 'EM "); for (counter=0;counter<LEXICON_LEN;counter++) { if (orig_words[counter][0] == '\0') { orig_words_len = counter; break; } } // Initialize original lexicon short lexicon[orig_words_len][WORD_LEN]; for (i=0;i<orig_words_len;i++) { letterCount(orig_words[i], lexicon[i]); lexicon[i][END] = i; } // Initialize input short inpt[WORD_LEN]; const char *inpt_str = "wellpunchmeinthefac"; letterCount(inpt_str, inpt); // Create Original Lexicon Queue... /* Add to orig_lex the index of the words that could possibly be spelled with the letters in the input. This list will be passed to the finding function */ lexiptr orig_lex; for (i=0;i<orig_words_len;i++) if (wordCheck(inpt, lexicon[i])) PushQ(&orig_lex, i); // Initialize results short temp_results[SINGLE_RESULT]; for (i=0;i<SINGLE_RESULT;i++) temp_results[i] = -1; short results[MAX_RESULTS][SINGLE_RESULT]; for (counter=0;counter<MAX_RESULTS;counter++) for (i=0;i<SINGLE_RESULT;i++) results[counter][i] = -1; /* Current Variables: char orig_words[][30], short lexicon[][27], short inpt[], short temp_results[], short results[][15], next_result */ puts(" GO! "); printf("Start = %d\n", time(NULL)); MainLoop(lexicon, inpt, temp_results, results, 0, orig_lex, orig_words); printf("Finish = %d, %i results found.\n", time(NULL), COUNT_RESULTS); for (counter=0;counter<50;counter++) { if (results[counter][0] == -1) continue; for (i=0;i<SINGLE_RESULT;i++) if (results[counter][i] != -1) printf("%s ", orig_words[results[counter][i]]); puts(""); } return 1; }