Join 109,579 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,572 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!
Alright, post your code from the contest if you'd like.
I only did problem 1 because #1, it was the only one I understood right away. And #2, I thought I could do it quickly. So without further ramblings by me....
Type Phrase Field Orig$ Field NewV$ Field Leng Field Tipe$ Field NPli End Type
ARead = ReadFile("Prob1.dat")
While Not Eof(ARead)
Test.Phrase = New Phrase Test\Orig$ = ReadLine(ARead)
Temp$=Lower$(Test\Orig$)
For a = 32 To 47 Temp$=Replace$(Temp$,Chr$(a),"") Next
For a = 58 To 64 Temp$=Replace$(Temp$,Chr$(a),"") Next
For a = 91 To 96 Temp$=Replace$(Temp$,Chr$(a),"") Next
For a = 123 To 126 Temp$=Replace$(Temp$,Chr$(a),"") Next
Test\NewV$ = Temp$ Test\Leng = Len(Test\NewV$)
If Len(Test\NewV$) Mod 2 = 0 Then Test\Tipe$ = "perfect" Else Test\Tipe$ = "odd" EndIf
If Test\Tipe$ = "odd" Then For a = 1 To Test\Leng/2 If Not Mid(Test\NewV$,a,1) = Mid(Test\NewV$,Test\Leng-a+1,1) Then Test\NPli=True EndIf Next EndIf
If Test\Tipe$ = "perfect" Then For a = 1 To Floor(Test\Leng/2) If Not Mid(Test\NewV$,a,1) = Mid(Test\NewV$,Test\Leng-a+1,1) Then Test\NPli=True EndIf Next EndIf
Wend
AWrite = WriteFile("Lattyware_prob1.out")
For Output.Phrase = Each Phrase If Output\Npli = False Then WriteLine(AWrite,Output\Orig$ + " - " + Output\Tipe$) EndIf Next
While Not Temp$ = " " a = a + 1 Num$=Num$+Temp$ Temp$=Mid$(Size$,a,1) Wend W = Num$
Num$="" Temp$=""
While Not a > Len(Size$) a = a + 1 Num$=Num$+Temp$ Temp$=Mid$(Size$,a,1) Wend H = Num$
Dim Block$(H,W)
Repeat TempNum = TempNum + 1 In$=ReadLine(ARead) For a = 1 To H Block$(a,TempNum) = Lower(Mid$(In$,a,1)) Next Until TempNum = W
For a = 1 To H If Not Block$(a,1) = "x" Then Block$(a,1) = "y" Next For a = 1 To H If Not Block$(a,W) = "x" Then Block$(a,W) = "y" Next For a = 1 To W If Not Block$(1,a) = "x" Then Block$(1,a) = "y" Next For a = 1 To W If Not Block$(H,a) = "x" Then Block$(H,a) = "y" Next
Round = True
While Round = True
Round = False
For a = 1 To H For b = 1 To W If Block$(a,b) = "y" Then If Not a = H Then If Block$(a+1,b) = "." Then Block$(a+1,b) = "y" Round = True EndIf EndIf If Not a = 1 Then If Block$(a-1,b) = "." Then Block$(a-1,b) = "y" Round = True EndIf EndIf If Not b = W Then If Block$(a,b+1) = "." Then Block$(a,b+1) = "y" Round = True EndIf EndIf If Not b = 1 Then If Block$(a,b-1) = "." Then Block$(a,b-1) = "y" Round = True EndIf EndIf EndIf Next Next
Wend
For a = 1 To H For b = 1 To W If Block$(a,b) = "." Then Area = Area + 1 Next Next
WriteLine(AWrite,Area)
ReadLine(ARead)
a = 0 W = 0 TempNum=0
Temp$="" Num$=""
Area = 0
Wend
End
And here is what I started on 2, which basically read the file.
CODE
Type Net Field Got$ End Type
Type Stamp Field Value Field Set Field TCase End Type
Type Set Field Total Field TCase Field SetNo End Type
Type TCase Field MaxStamps Field NumOfSets Field TCaseNumb End Type
A1.TCase = New TCase A1\TCaseNumb = Total A1\MaxStamps = Test A1\NumOfSets = ReadLine(ARead)
For Temp1 = 1 To A1\NumOfSets A2.Set = New Set A2\TCase = A1\TCaseNumb A2\SetNo = Temp1 In$ = ReadLine(ARead) Split(In$," ") Get.Net = First Net A2\Total = Get\Got$ For Temp2 = 1 To A2\Total A3.Stamp = New Stamp Get = After Get A3\Value = Get\Got$ A3\Set = A2\SetNo A3\TCase = A1\TCaseNumb Next Next
Wend
.Done
Print GetStamps$(3,1)
WaitKey() End
Function GetStamps$(TCase,Set) For A3.Stamp = Each Stamp If A3\Set = Set Then If A3\TCase = TCase Then Out$ = Out$ + A3\Value+"," EndIf EndIf Next Return Out$ End Function
Function Split(In$,C$) CleanNets() ANew = True For a = 1 To Len(In$) If ANew = True Then Split.Net = New Net Split\Got$ = Split\Got$ + Mid$(In$,a,1) ANew = False Else Split.Net = Last Net If Mid$(In$,a,1) = C$ Then ANew = True Else Split\Got$ = Split\Got$ + Mid$(In$,a,1) EndIf EndIf Next End Function
Function CleanNets() For Clean.Net = Each Net Delete Clean Next End Function
1 was pretty easy, just stripping it and reading in the letters from each end to see if it's a palindrome.
4 took me a while, but I eventually realised all non-enclosed space must connect to the edges, and the edges (unless they are walls) must be open space. Therefore you can just flood from the edges inwards, untill you can't anymore, and the areas left untouched, are enclosed space.
if($handle = @fopen($output, 'w+')){ for($i = 0; $i < count($line); $i++){ fputs($handle, testLine($line[$i])); } fclose($handle); } else { if ($handle = @fopen($output, 'a+')) { for($i = 0; $i < count($line); $i++){ fputs($handle, testLine($line[$i])); } fclose($handle); } else { echo ("<p>File <b>$output</b> was not found, nor was it possible to create it.<br><br>"); echo ("Please make sure your PHP settings are set to allow output of text files, then try again.</p>"); } }
function getFile($file){ if ($grab = @fopen($file, 'r')) { echo ("<p><br>"); while (!feof($grab)) { echo (fgets($grab, 1024) . "<br>"); } fclose($grab); echo ("</p>"); } }
/* ************************************** Dream.in.code 48 Hour competition Member Name: Red|5 Compiler: PHP Version 5.0.4 Language Used: PHP Problem Name: #2 AUTOMATED LETTER HANDLER ************************************** */
int getNumChar(FILE *fp) { int numChar = 0; char c = 0;
while((c = getc(fp)) != EOF) { if( c != '\n' && c != 33 && c != 34 && c != 39 && c != 40 && c != 41 && c != 44 && c != 45 && c != 46 && c != 47 && c != 58 && c != 59 && c != 63 && c!= 91 && c != 92 && c != 93 && c != 95 && c != 123 && c != 125 && c != 130 && c != 132 && c != 139 && c != 145 && c != 146 && c != 147 && c != 148 && c != 150 && c != 151 && c != 155 && c != 161 && c != 171 && c != 173 && c != 183 && c != 187 && c != ' ') { numChar++; } else if(c == '\n' || (c != 33 && c != 34 && c != 39 && c != 40 && c != 41 && c != 44 && c != 45 && c != 46 && c != 47 && c != 58 && c != 59 && c != 63 && c!= 91 && c != 92 && c != 93 && c != 95 && c != 123 && c != 125 && c != 130 && c != 132 && c != 139 && c != 145 && c != 146 && c != 147 && c != 148 && c != 150 && c != 151 && c != 155 && c != 161 && c != 171 && c != 173 && c != 183 && c != 187 ) || c == ' ') { return numChar; } }
return 0; // should never return this! }
int getNumLines(FILE *fp) { int numLines = 0; char c = 0;
void readWord(FILE *fp, char *buffer) { char c = 0; int i = 0; while((c = getc(fp)) != EOF) { if( c != '\n' && c != 33 && c != 34 && c != 39 && c != 40 && c != 41 && c != 44 && c != 45 && c != 46 && c != 47 && c != 58 && c != 59 && c != 63 && c!= 91 && c != 92 && c != 93 && c != 95 && c != 123 && c != 125 && c != 130 && c != 132 && c != 139 && c != 145 && c != 146 && c != 147 && c != 148 && c != 150 && c != 151 && c != 155 && c != 161 && c != 171 && c != 173 && c != 183 && c != 187 && c != ' ') { buffer[i++] = c; } else if (c == '\n' || (c != 33 && c != 34 && c != 39 && c != 40 && c != 41 && c != 44 && c != 45 && c != 46 && c != 47 && c != 58 && c != 59 && c != 63 && c!= 91 && c != 92 && c != 93 && c != 95 && c != 123 && c != 125 && c != 130 && c != 132 && c != 139 && c != 145 && c != 146 && c != 147 && c != 148 && c != 150 && c != 151 && c != 155 && c != 161 && c != 171 && c != 173 && c != 183 && c != 187 ) || c == ' ') { return; } } }
int matches = 0; int numCh; // chr is the middle letter for odds! if(isEven != true) numCh = chr+1; else numCh = chr;
cout << endl << "Comparing part one's inverse to part two" << endl; for(int i = 0, j = numCh; i <= chr, j < word.numChar; i++, j++) { cout << endl << "Performing Algorithm <Anna> to " << partOne[0].wInverse[i] << " and " << partTwo[0].word[j] << endl; if(partOne[0].wInverse[i] == partTwo[0].word[j]) { matches++; cout << "Match Found -> " << partOne[0].wInverse[i] << endl; cout << "Checking for full-text match." << endl; if(matches == chr) { cout << "Full-text match found!" << endl; cout << "VALUE -> PERFECT!" << endl; cout << "Test successfully done!" << endl << endl; return 1; } } else { if(i+1 == chr && matches == 0) { cout << "No match!" << endl; cout << "No total matches found." << endl; cout << "This line is not consist of any palindromic letters!" << endl; cout << "Test successfully done!" << endl << endl; return 0; } else if(i+1 != chr) { cout << "No match!" << endl; cout << "Testing another character" << endl; cout << "Character To Test: " << partOne[0].wInverse[i+1] << endl; } else if(i+1 == chr && matches > 0) { cout << matches << " matches found but no full-text match found!" << endl; cout << "VALUE -> ODD" << endl; cout << "Test successfully done!" << endl << endl; return 0; } } } return 0; }
int AlgorithmMirror(__line line) { __word fullText[1]; // it is gonna look like 1 word. int totalChar = 0; int chr = 0; bool isEven = false;
strcpy(fullText[0].word, "");
for(int i = 0; i <= line.numWord; i++) { totalChar += line.word[i].numChar; strcat(fullText[0].word, line.word[i].word); } cout << "Merged the numChar of each word in the line: " << totalChar << endl; cout << "Assembeled the line as follow: " << fullText[0].word << endl;
int a = getNumLines(fp); // Get the number of lines rewind(fp);
for(int i = 0; i < a; i++) { line[i].numWord = getNumWord(SPEC_Line, fp); // Get the number of words by using SPEC_Body cout << "Number of Words: " << line[i].numWord << " in line " << i << endl; } rewind(fp); cout << "Number of Lines " << a << " // Note SPEC_Body sees whole text as a line" << endl;
for(int l = 0; l < a; l++) { for(int m = 0; m < line[l].numWord; m++) { line[l].word[m].numChar = getNumChar(fp); } } rewind(fp); cout << endl;
Looking good, guys...although I will note that C++ does have the tools to accomplish the program in far fewer lines than shown....but this works, which is all that matters!
ifstream infile("prob3.dat"); ofstream outfile("zyruz_prob3.out"); struct station { int nr; int cells; vector<int> target; int target_num; bool hit_t; bool hit_l; };