Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › The Programming Challenge Master Thread
New Posts  All Forums:Forum Nav:

The Programming Challenge Master Thread - Page 19

post #181 of 263
Thread Starter 
PROGRAMMING CHALLENGE #5 POSTED
MacBook Pro 13"
(6 items)
 
 
Desktop
(13 items)
 
CPUGraphicsRAMHard Drive
Intel i5 3210 @ 2.5 GHz Intel HD4000 4 GB DDR3 @ 1600 MHz 500 GB @ 5400 RPM 
OSMonitor
OSX Mountain Lion 13.3" @ 1280 x 800 
CPUGraphicsRAMHard Drive
Intel i5 480m@2.67GHz AMD Radeon Mobility 5650 4GB DDR3 500GB 
OSMonitor
Windows 7 64bit HP 15.6" 1366x768 
CPUMotherboardGraphicsRAM
E7500 Intel...:( MSI GTS250 1GB 2GB 
Hard DriveOSMonitorPower
250GB Windows XP 17" LG CRT 1280x768@85hz 400W 
  hide details  
Reply
MacBook Pro 13"
(6 items)
 
 
Desktop
(13 items)
 
CPUGraphicsRAMHard Drive
Intel i5 3210 @ 2.5 GHz Intel HD4000 4 GB DDR3 @ 1600 MHz 500 GB @ 5400 RPM 
OSMonitor
OSX Mountain Lion 13.3" @ 1280 x 800 
CPUGraphicsRAMHard Drive
Intel i5 480m@2.67GHz AMD Radeon Mobility 5650 4GB DDR3 500GB 
OSMonitor
Windows 7 64bit HP 15.6" 1366x768 
CPUMotherboardGraphicsRAM
E7500 Intel...:( MSI GTS250 1GB 2GB 
Hard DriveOSMonitorPower
250GB Windows XP 17" LG CRT 1280x768@85hz 400W 
  hide details  
Reply
post #182 of 263
Is it too late to try number 1# now? biggrin.gif

Warning: Spoiler! (Click to show)
Code:
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
        int input;
        int number = 0;
        string::iterator it;
        string output = "*";

        cout << "Input: ";
        cin >> input;
        it = output.begin()+number;

Start:

        if(number < input){
                number++;
                cout << output << endl;
                output += "*";
                goto Start;
        }
        else{
                output.erase(it);
                if(output != ""){
                        cout << output << endl;
                        goto Start;
                }
        }

        cout << endl;
        system("pause"); //cin.ignore() didn't work
        return 0;
}



No idea if I did it correctly, but at least it works! thumb.gif

285
Edited by bruflot - 6/2/12 at 12:38pm
Citra ♥
(15 items)
 
Big Mac
(10 items)
 
 
CPUMotherboardGraphicsRAM
[Intel] Core i7 2600K [Asus] P8Z68-V Pro [Gainward] Geforce 9800 GTX+ [Corsair] Vengeance 16GB @ 1600 
Hard DriveHard DriveCoolingOS
[Kingston] HyperX 120GB SSD [Intel] 520 series 60GB [Corsair] H80 [Canonical] Ubuntu 12.10 
MonitorKeyboardPowerCase
[BenQ] XL2420T [Corsair] Vengeance K60 Performance [OCZ] ZX 850W [CM] Storm Enforcer 
MouseAudioOther
[Razer] Mamba 4G 2012 [Beats] urBeats [NZXT] 24/8/6 pin extensions 
CPUMotherboardGraphicsRAM
[Intel] Core i5-3210M [Apple] Proprietary [Intel] HD 4000 [Hynix] H5TC2G83CFR DDR3L 8GB 
Hard DriveOSMonitorKeyboard
[Samsung] 128GB SSD [Apple] OS X 10.8.2 ML 13" 2560x1600 Retina [Apple] Backlit Keyboard 
CaseMouse Pad
[Apple] Unibody [Apple] Trackpad 
  hide details  
Reply
Citra ♥
(15 items)
 
Big Mac
(10 items)
 
 
CPUMotherboardGraphicsRAM
[Intel] Core i7 2600K [Asus] P8Z68-V Pro [Gainward] Geforce 9800 GTX+ [Corsair] Vengeance 16GB @ 1600 
Hard DriveHard DriveCoolingOS
[Kingston] HyperX 120GB SSD [Intel] 520 series 60GB [Corsair] H80 [Canonical] Ubuntu 12.10 
MonitorKeyboardPowerCase
[BenQ] XL2420T [Corsair] Vengeance K60 Performance [OCZ] ZX 850W [CM] Storm Enforcer 
MouseAudioOther
[Razer] Mamba 4G 2012 [Beats] urBeats [NZXT] 24/8/6 pin extensions 
CPUMotherboardGraphicsRAM
[Intel] Core i5-3210M [Apple] Proprietary [Intel] HD 4000 [Hynix] H5TC2G83CFR DDR3L 8GB 
Hard DriveOSMonitorKeyboard
[Samsung] 128GB SSD [Apple] OS X 10.8.2 ML 13" 2560x1600 Retina [Apple] Backlit Keyboard 
CaseMouse Pad
[Apple] Unibody [Apple] Trackpad 
  hide details  
Reply
post #183 of 263
Thread Starter 
Quote:
Originally Posted by bruflot View Post

Is it too late to try number 1# now? biggrin.gifWarning: Spoiler! (Click to show)
Code:
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
        int input;
        int number = 0;
        string::iterator it;
        string output = "*";
        cout << "Input: ";
        cin >> input;
        it = output.begin()+number;
Start:
        if(number < input){
                number++;
                cout << output << endl;
                output += "*";
                goto Start;
        }
        else{
                output.erase(it);
                if(output != ""){
                        cout << output << endl;
                        goto Start;
                }
        }
        cout << endl;
        system("pause"); //cin.ignore() didn't work
        return 0;
}
No idea if I did it correctly, but at least it works! thumb.gif
285

Oh hi there. biggrin.gif

Didn't read the code properly but one little mistake I can pick out is that in your output, n number of stars (n = 5 in your input) occurs twice.
It should be:

*
**
***
****
*****
****
***
**
*

As in 5 stars occur once, not twice.

But then again, the basic code is fine and you know how to use loops to provide a solution to the problem of the challenge, so I guess it's fine.

Good job. thumb.gif

It would be a nice idea to try the newer challenges too. smile.gif
MacBook Pro 13"
(6 items)
 
 
Desktop
(13 items)
 
CPUGraphicsRAMHard Drive
Intel i5 3210 @ 2.5 GHz Intel HD4000 4 GB DDR3 @ 1600 MHz 500 GB @ 5400 RPM 
OSMonitor
OSX Mountain Lion 13.3" @ 1280 x 800 
CPUGraphicsRAMHard Drive
Intel i5 480m@2.67GHz AMD Radeon Mobility 5650 4GB DDR3 500GB 
OSMonitor
Windows 7 64bit HP 15.6" 1366x768 
CPUMotherboardGraphicsRAM
E7500 Intel...:( MSI GTS250 1GB 2GB 
Hard DriveOSMonitorPower
250GB Windows XP 17" LG CRT 1280x768@85hz 400W 
  hide details  
Reply
MacBook Pro 13"
(6 items)
 
 
Desktop
(13 items)
 
CPUGraphicsRAMHard Drive
Intel i5 3210 @ 2.5 GHz Intel HD4000 4 GB DDR3 @ 1600 MHz 500 GB @ 5400 RPM 
OSMonitor
OSX Mountain Lion 13.3" @ 1280 x 800 
CPUGraphicsRAMHard Drive
Intel i5 480m@2.67GHz AMD Radeon Mobility 5650 4GB DDR3 500GB 
OSMonitor
Windows 7 64bit HP 15.6" 1366x768 
CPUMotherboardGraphicsRAM
E7500 Intel...:( MSI GTS250 1GB 2GB 
Hard DriveOSMonitorPower
250GB Windows XP 17" LG CRT 1280x768@85hz 400W 
  hide details  
Reply
post #184 of 263
Ohwell, thanks though biggrin.gif
I figured that I'd might as well start with the first one, since I'm quite a noob with "pure C++". (Most of my skills are with game engines, such as Unreal/Unity)

I'll try to fix my code first though, I'm on a Mac now, hope that doesn't matter? rolleyes.gif

Edit: Ok, fixed the code! First app I've ever done in OS X too smile.gif

Code (Click to show)
Code:
void OCN1(int input){
    int n = 0;
    int i = input - 1;
    string chr = "*";
    
Start:
    
    if(n < input){
        n++;
        cout << chr << endl;
        chr += "*";
        goto Start;
    }
    else{
        chr.erase(i);
        i--;
        cout << chr << endl;
        if(chr != "*")
            goto Start;
    }
}

324

(Xcode created that stupid copyright thing..)

Oh, and I hope you saw that last part in my other post from the other thread?
85
Edited by bruflot - 6/16/12 at 1:25pm
Citra ♥
(15 items)
 
Big Mac
(10 items)
 
 
CPUMotherboardGraphicsRAM
[Intel] Core i7 2600K [Asus] P8Z68-V Pro [Gainward] Geforce 9800 GTX+ [Corsair] Vengeance 16GB @ 1600 
Hard DriveHard DriveCoolingOS
[Kingston] HyperX 120GB SSD [Intel] 520 series 60GB [Corsair] H80 [Canonical] Ubuntu 12.10 
MonitorKeyboardPowerCase
[BenQ] XL2420T [Corsair] Vengeance K60 Performance [OCZ] ZX 850W [CM] Storm Enforcer 
MouseAudioOther
[Razer] Mamba 4G 2012 [Beats] urBeats [NZXT] 24/8/6 pin extensions 
CPUMotherboardGraphicsRAM
[Intel] Core i5-3210M [Apple] Proprietary [Intel] HD 4000 [Hynix] H5TC2G83CFR DDR3L 8GB 
Hard DriveOSMonitorKeyboard
[Samsung] 128GB SSD [Apple] OS X 10.8.2 ML 13" 2560x1600 Retina [Apple] Backlit Keyboard 
CaseMouse Pad
[Apple] Unibody [Apple] Trackpad 
  hide details  
Reply
Citra ♥
(15 items)
 
Big Mac
(10 items)
 
 
CPUMotherboardGraphicsRAM
[Intel] Core i7 2600K [Asus] P8Z68-V Pro [Gainward] Geforce 9800 GTX+ [Corsair] Vengeance 16GB @ 1600 
Hard DriveHard DriveCoolingOS
[Kingston] HyperX 120GB SSD [Intel] 520 series 60GB [Corsair] H80 [Canonical] Ubuntu 12.10 
MonitorKeyboardPowerCase
[BenQ] XL2420T [Corsair] Vengeance K60 Performance [OCZ] ZX 850W [CM] Storm Enforcer 
MouseAudioOther
[Razer] Mamba 4G 2012 [Beats] urBeats [NZXT] 24/8/6 pin extensions 
CPUMotherboardGraphicsRAM
[Intel] Core i5-3210M [Apple] Proprietary [Intel] HD 4000 [Hynix] H5TC2G83CFR DDR3L 8GB 
Hard DriveOSMonitorKeyboard
[Samsung] 128GB SSD [Apple] OS X 10.8.2 ML 13" 2560x1600 Retina [Apple] Backlit Keyboard 
CaseMouse Pad
[Apple] Unibody [Apple] Trackpad 
  hide details  
Reply
post #185 of 263
Thread Starter 
It's different from what I would normally do (I'd just write two for loops with one with increasing number of * and one with decreasing) but yours works fine too. smile.gif
MacBook Pro 13"
(6 items)
 
 
Desktop
(13 items)
 
CPUGraphicsRAMHard Drive
Intel i5 3210 @ 2.5 GHz Intel HD4000 4 GB DDR3 @ 1600 MHz 500 GB @ 5400 RPM 
OSMonitor
OSX Mountain Lion 13.3" @ 1280 x 800 
CPUGraphicsRAMHard Drive
Intel i5 480m@2.67GHz AMD Radeon Mobility 5650 4GB DDR3 500GB 
OSMonitor
Windows 7 64bit HP 15.6" 1366x768 
CPUMotherboardGraphicsRAM
E7500 Intel...:( MSI GTS250 1GB 2GB 
Hard DriveOSMonitorPower
250GB Windows XP 17" LG CRT 1280x768@85hz 400W 
  hide details  
Reply
MacBook Pro 13"
(6 items)
 
 
Desktop
(13 items)
 
CPUGraphicsRAMHard Drive
Intel i5 3210 @ 2.5 GHz Intel HD4000 4 GB DDR3 @ 1600 MHz 500 GB @ 5400 RPM 
OSMonitor
OSX Mountain Lion 13.3" @ 1280 x 800 
CPUGraphicsRAMHard Drive
Intel i5 480m@2.67GHz AMD Radeon Mobility 5650 4GB DDR3 500GB 
OSMonitor
Windows 7 64bit HP 15.6" 1366x768 
CPUMotherboardGraphicsRAM
E7500 Intel...:( MSI GTS250 1GB 2GB 
Hard DriveOSMonitorPower
250GB Windows XP 17" LG CRT 1280x768@85hz 400W 
  hide details  
Reply
post #186 of 263
Is it the C experience speaking in me freaking out on the use of goto's or is it just as unadvised to use in C++ too? Reminds me of assembly a little smile.gif
Footrest
(17 items)
 
server
(17 items)
 
HTPC
(12 items)
 
CPUMotherboardGraphicsRAM
2 x Xeon L5520 Supermicro X8DTL-i HD4550 Samsung 6x4GB ECC 
Hard DriveHard DriveCoolingOS
3 x 2TB WD Green 160GB WD Blue Hyper 212+ and EVO ESXi 
OSOSOSPower
unRaid pfSense Ubuntu CX430v2 
CaseOtherOther
CM Elite 331 TP-Link TG-3269 Sil3512 Sata controller 
CPUMotherboardRAMHard Drive
i3-2100T Asus P8H61-I Geil Black Dragon 1333 2x2GB PXE Network boot 
Optical DriveCoolingOSMonitor
OEM Slim DVD Burner Scythe Big-Shuriken OpenElec Panasonic TX-P42G30E 42" HDTV 
KeyboardCase
Lenovo n5901a Silverstone SG-05 
  hide details  
Reply
Footrest
(17 items)
 
server
(17 items)
 
HTPC
(12 items)
 
CPUMotherboardGraphicsRAM
2 x Xeon L5520 Supermicro X8DTL-i HD4550 Samsung 6x4GB ECC 
Hard DriveHard DriveCoolingOS
3 x 2TB WD Green 160GB WD Blue Hyper 212+ and EVO ESXi 
OSOSOSPower
unRaid pfSense Ubuntu CX430v2 
CaseOtherOther
CM Elite 331 TP-Link TG-3269 Sil3512 Sata controller 
CPUMotherboardRAMHard Drive
i3-2100T Asus P8H61-I Geil Black Dragon 1333 2x2GB PXE Network boot 
Optical DriveCoolingOSMonitor
OEM Slim DVD Burner Scythe Big-Shuriken OpenElec Panasonic TX-P42G30E 42" HDTV 
KeyboardCase
Lenovo n5901a Silverstone SG-05 
  hide details  
Reply
post #187 of 263
Quote:
Originally Posted by Aximous View Post

Is it the C experience speaking in me freaking out on the use of goto's or is it just as unadvised to use in C++ too? Reminds me of assembly a little smile.gif

In general, goto's are a no-no. Not that there's anything fundamentaly wrong with them, but it almost always makes code much harder to read and usually implies that the code's structure isn't very good. Of course, on the assembly level, all loops are just conditional gotos smile.gif

Also,

163
Workstation
(19 items)
 
  
CPUMotherboardGraphicsGraphics
Intel i7 920 c0 @ 3.50 Asus Sabertooth X58 Nvidia gtx 570 Nvidia gtx 210 
RAMHard DriveOptical DriveOptical Drive
12 GB (Patriot 4GB DDR3 1600 Mhz + G.Skill Ripj... OCZ Vertex II 60GB + x2 WD 1TB + WD 500 GB Lite-On DVD Burner LG Blu Ray Burner 
OSMonitorMonitorMonitor
Windows 8 Professional x64, Arch Linux x64 Samsung 22 inch 1920x1080 60Hz Asus 23 inch 1920x1080 IPS Acer 19 inch 1600x900 
KeyboardPowerCaseMouse
Logitech g11 Corsair 750 Watt NZXT Tempest Razer deathadder 3500 dpi 
Mouse PadAudioAudio
OCZ Audigy SE Sony MDR-V6 
  hide details  
Reply
Workstation
(19 items)
 
  
CPUMotherboardGraphicsGraphics
Intel i7 920 c0 @ 3.50 Asus Sabertooth X58 Nvidia gtx 570 Nvidia gtx 210 
RAMHard DriveOptical DriveOptical Drive
12 GB (Patriot 4GB DDR3 1600 Mhz + G.Skill Ripj... OCZ Vertex II 60GB + x2 WD 1TB + WD 500 GB Lite-On DVD Burner LG Blu Ray Burner 
OSMonitorMonitorMonitor
Windows 8 Professional x64, Arch Linux x64 Samsung 22 inch 1920x1080 60Hz Asus 23 inch 1920x1080 IPS Acer 19 inch 1600x900 
KeyboardPowerCaseMouse
Logitech g11 Corsair 750 Watt NZXT Tempest Razer deathadder 3500 dpi 
Mouse PadAudioAudio
OCZ Audigy SE Sony MDR-V6 
  hide details  
Reply
post #188 of 263
Thread Starter 
Quote:
Originally Posted by Aximous View Post

Is it the C experience speaking in me freaking out on the use of goto's or is it just as unadvised to use in C++ too? Reminds me of assembly a little smile.gif

Quote:
Originally Posted by Waffleboy View Post

In general, goto's are a no-no. Not that there's anything fundamentaly wrong with them, but it almost always makes code much harder to read and usually implies that the code's structure isn't very good. Of course, on the assembly level, all loops are just conditional gotos smile.gif
Also,
163

Yea, that through me off a bit when I first read his code.

I don't think I've ever really seen GOTOs used in C++.
MacBook Pro 13"
(6 items)
 
 
Desktop
(13 items)
 
CPUGraphicsRAMHard Drive
Intel i5 3210 @ 2.5 GHz Intel HD4000 4 GB DDR3 @ 1600 MHz 500 GB @ 5400 RPM 
OSMonitor
OSX Mountain Lion 13.3" @ 1280 x 800 
CPUGraphicsRAMHard Drive
Intel i5 480m@2.67GHz AMD Radeon Mobility 5650 4GB DDR3 500GB 
OSMonitor
Windows 7 64bit HP 15.6" 1366x768 
CPUMotherboardGraphicsRAM
E7500 Intel...:( MSI GTS250 1GB 2GB 
Hard DriveOSMonitorPower
250GB Windows XP 17" LG CRT 1280x768@85hz 400W 
  hide details  
Reply
MacBook Pro 13"
(6 items)
 
 
Desktop
(13 items)
 
CPUGraphicsRAMHard Drive
Intel i5 3210 @ 2.5 GHz Intel HD4000 4 GB DDR3 @ 1600 MHz 500 GB @ 5400 RPM 
OSMonitor
OSX Mountain Lion 13.3" @ 1280 x 800 
CPUGraphicsRAMHard Drive
Intel i5 480m@2.67GHz AMD Radeon Mobility 5650 4GB DDR3 500GB 
OSMonitor
Windows 7 64bit HP 15.6" 1366x768 
CPUMotherboardGraphicsRAM
E7500 Intel...:( MSI GTS250 1GB 2GB 
Hard DriveOSMonitorPower
250GB Windows XP 17" LG CRT 1280x768@85hz 400W 
  hide details  
Reply
post #189 of 263
Okay, that's what I thought, thanks. Oh how much I love xkcd thumb.gif
Footrest
(17 items)
 
server
(17 items)
 
HTPC
(12 items)
 
CPUMotherboardGraphicsRAM
2 x Xeon L5520 Supermicro X8DTL-i HD4550 Samsung 6x4GB ECC 
Hard DriveHard DriveCoolingOS
3 x 2TB WD Green 160GB WD Blue Hyper 212+ and EVO ESXi 
OSOSOSPower
unRaid pfSense Ubuntu CX430v2 
CaseOtherOther
CM Elite 331 TP-Link TG-3269 Sil3512 Sata controller 
CPUMotherboardRAMHard Drive
i3-2100T Asus P8H61-I Geil Black Dragon 1333 2x2GB PXE Network boot 
Optical DriveCoolingOSMonitor
OEM Slim DVD Burner Scythe Big-Shuriken OpenElec Panasonic TX-P42G30E 42" HDTV 
KeyboardCase
Lenovo n5901a Silverstone SG-05 
  hide details  
Reply
Footrest
(17 items)
 
server
(17 items)
 
HTPC
(12 items)
 
CPUMotherboardGraphicsRAM
2 x Xeon L5520 Supermicro X8DTL-i HD4550 Samsung 6x4GB ECC 
Hard DriveHard DriveCoolingOS
3 x 2TB WD Green 160GB WD Blue Hyper 212+ and EVO ESXi 
OSOSOSPower
unRaid pfSense Ubuntu CX430v2 
CaseOtherOther
CM Elite 331 TP-Link TG-3269 Sil3512 Sata controller 
CPUMotherboardRAMHard Drive
i3-2100T Asus P8H61-I Geil Black Dragon 1333 2x2GB PXE Network boot 
Optical DriveCoolingOSMonitor
OEM Slim DVD Burner Scythe Big-Shuriken OpenElec Panasonic TX-P42G30E 42" HDTV 
KeyboardCase
Lenovo n5901a Silverstone SG-05 
  hide details  
Reply
post #190 of 263
Wait, are we talking about my code? sad-smiley-002.gif
So goto is a no-no?
Citra ♥
(15 items)
 
Big Mac
(10 items)
 
 
CPUMotherboardGraphicsRAM
[Intel] Core i7 2600K [Asus] P8Z68-V Pro [Gainward] Geforce 9800 GTX+ [Corsair] Vengeance 16GB @ 1600 
Hard DriveHard DriveCoolingOS
[Kingston] HyperX 120GB SSD [Intel] 520 series 60GB [Corsair] H80 [Canonical] Ubuntu 12.10 
MonitorKeyboardPowerCase
[BenQ] XL2420T [Corsair] Vengeance K60 Performance [OCZ] ZX 850W [CM] Storm Enforcer 
MouseAudioOther
[Razer] Mamba 4G 2012 [Beats] urBeats [NZXT] 24/8/6 pin extensions 
CPUMotherboardGraphicsRAM
[Intel] Core i5-3210M [Apple] Proprietary [Intel] HD 4000 [Hynix] H5TC2G83CFR DDR3L 8GB 
Hard DriveOSMonitorKeyboard
[Samsung] 128GB SSD [Apple] OS X 10.8.2 ML 13" 2560x1600 Retina [Apple] Backlit Keyboard 
CaseMouse Pad
[Apple] Unibody [Apple] Trackpad 
  hide details  
Reply
Citra ♥
(15 items)
 
Big Mac
(10 items)
 
 
CPUMotherboardGraphicsRAM
[Intel] Core i7 2600K [Asus] P8Z68-V Pro [Gainward] Geforce 9800 GTX+ [Corsair] Vengeance 16GB @ 1600 
Hard DriveHard DriveCoolingOS
[Kingston] HyperX 120GB SSD [Intel] 520 series 60GB [Corsair] H80 [Canonical] Ubuntu 12.10 
MonitorKeyboardPowerCase
[BenQ] XL2420T [Corsair] Vengeance K60 Performance [OCZ] ZX 850W [CM] Storm Enforcer 
MouseAudioOther
[Razer] Mamba 4G 2012 [Beats] urBeats [NZXT] 24/8/6 pin extensions 
CPUMotherboardGraphicsRAM
[Intel] Core i5-3210M [Apple] Proprietary [Intel] HD 4000 [Hynix] H5TC2G83CFR DDR3L 8GB 
Hard DriveOSMonitorKeyboard
[Samsung] 128GB SSD [Apple] OS X 10.8.2 ML 13" 2560x1600 Retina [Apple] Backlit Keyboard 
CaseMouse Pad
[Apple] Unibody [Apple] Trackpad 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › The Programming Challenge Master Thread