Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programming Challenge (Out-of-Date)
New Posts  All Forums:Forum Nav:

Programming Challenge (Out-of-Date) - Page 12  

Poll Results: Are you interested in participating in and/or helping organise and post these programming challenges?

 
  • 100% (2)
    I want to participate.
  • 0% (0)
    I want to contribute by helping posting and organise these challenges.
  • 0% (0)
    I'll only take part if other people are willing to participate.
  • 0% (0)
    I can help and participate - I love programming!
  • 0% (0)
    I do not wish to participate or help.
2 Total Votes  
post #111 of 306
Well, hope this is how you "sign up" for the competition, here's my entry,
it does a bit more than what was required, but well, was a fun exercise!
Will attach the GUI I made aswell (Zipped) - Exe + Source!
- have fun ^.^
written in C# - spent a lot of time thinking about performance of the shift operations etc. (Few hours I think, this includes doing benchmarks XD) But think I finally managed to get something that performs,
at least reasonably descent:

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Substitution_Encoder1
{
public class EncodingController
{
private int shift = 0;
private List<char> letters = new List<char>();

public EncodingController()
{
for (int i = 0; i < 255; i++)
{
if (char.IsLetterOrDigit((char)i))
letters.Add((char)i);
}
this.shift = 0;
}

public void ShiftLeft(int amount)
{
this.shift = (this.shift + amount) % this.Length;
}

public void Reset()
{
this.shift = 0;
}

public void ShiftRight(int amount)
{
this.shift = (this.shift - amount) % this.Length;
this.shift = this.shift < 0 ? this.Length + this.shift : this.shift;
}

public int Length
{
get { return this.letters.Count; }
}

public string Encode(string txt)
{
char[] res = new char[txt.Length];
for (int i = 0; i < txt.Length; i++)
{
if (char.IsLetterOrDigit(txt[i]))
res[i] = this.letters[(this.letters.IndexOf(txt[i]) + this.shift) % this.letters.Count];
else
res[i] = txt[i];
//res[i] = (byte)((txt[i] + shift) % 256);
}
return new string(res);
}

public string Decode(string txt)
{
string res = string.Empty;
foreach (char c in txt)
{
if (char.IsLetterOrDigit(c))
{
int idx = (this.letters.IndexOf(c) - this.shift) % this.letters.Count;
idx = idx < 0 ? this.letters.Count + idx : idx;
res += this.letters[idx];
}
else
res += c;
}
return res;
}

public string Encode(string txt, byte[] key)
{
this.Reset();
char[] res = new char[txt.Length];
for (int i = 0; i < txt.Length; i++)
{
foreach (byte b in key)
this.ShiftRight(b);
//res[i] = (byte)((txt[i] + shift) % 256);
if (char.IsLetterOrDigit(txt[i]))
res[i] = this.letters[(this.letters.IndexOf(txt[i]) + this.shift) % this.letters.Count];
else
res[i] = txt[i];
}
return new string(res);
}

public string Decode(string txt, byte[] key)
{
this.Reset();
string res = string.Empty;
foreach (char c in txt)
{
foreach (byte kb in key)
this.ShiftRight(kb);
//res += (char)((byte)((b - shift) % 256));
if (char.IsLetterOrDigit(c))
{
int idx = (this.letters.IndexOf(c) - this.shift) % this.letters.Count;
idx = idx < 0 ? this.letters.Count + idx : idx;
res += this.letters[idx];
}
else
res += c;
}
return res;
}
}
}
Edit1: Revised some of the code - especially the way the shift and encoding / decoding is happening - should now perform a lot better - and look better too
Re-up'ed the source + exe.

Edit2: Apparently I didn't read the rules XD Was supposed to leave punctuation alone :/
Well, here goes another one, should still be performing "within expected parameters", just a bit different... Spaces and punctuation are left alone! Only thing being encoded are letters and digits (according to .Net atleast)

Edit3: Should've read the next few posts i guess o.O This challenge ended 3 years ago? XD Talk about late handin
The first post said the current challenge was on Post #10, so didn't think a lot about that woot!
Anyways, Is there anything going on here? Or?
Edited by T0yK4T - 5/2/10 at 1:28pm
My new box!
(13 items)
 
  
CPUMotherboardGraphicsRAM
I7 920 Asus Rampage II Extreme R.O.G. Inno3D Nvidia GeForce GTX 480 3x2 GB Corsair Dominator GT 
Hard DriveOptical DriveOSMonitor
1x120 GB OCZ Vertex Series +2x1 TB WD Caviar Black None yet - incomming budget one Windows 7 Home Premium N (Yes i OWN it o.O) Syncmaster 226BW + Philips Brilliance 240SW 
KeyboardPowerCaseMouse
New one incomming Chieftec Super Series CFT-1000G-DF Coolermaster HAF 932 SteelSeries Ikari Laser 
Mouse Pad
Inno3D pad that came with the GFX 
  hide details  
My new box!
(13 items)
 
  
CPUMotherboardGraphicsRAM
I7 920 Asus Rampage II Extreme R.O.G. Inno3D Nvidia GeForce GTX 480 3x2 GB Corsair Dominator GT 
Hard DriveOptical DriveOSMonitor
1x120 GB OCZ Vertex Series +2x1 TB WD Caviar Black None yet - incomming budget one Windows 7 Home Premium N (Yes i OWN it o.O) Syncmaster 226BW + Philips Brilliance 240SW 
KeyboardPowerCaseMouse
New one incomming Chieftec Super Series CFT-1000G-DF Coolermaster HAF 932 SteelSeries Ikari Laser 
Mouse Pad
Inno3D pad that came with the GFX 
  hide details  
post #112 of 306
oldschool style coder:

md5.php
Code:

<?php

$q = $_GET['q'];

$response = md5($q);

echo $response


?>
md5test.htm
Code:
<html>
<body>

<H1> MD5 Convertor
</H1>

<script type="text/javascript">

function notEmpty(){
var text = document.getElementById('submit').value;
window.XMLHttpRequest
 {
xmlhttp=new XMLHttpRequest();
   }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    response.innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","md5.php?q="+text,true);
xmlhttp.send();

}


</script>

<div>
<table border="0">
<tr><td id="response">please enter a text here</td></tr>
<input type="text" id='submit' name="submit">

<tr><th colspan=2><input type="submit" onclick='notEmpty()' name="submit" value="Ok"></th></tr>
</h1>

</table>
</div>



</body>
</html>
I'm not sure if this is allowed.
The golden rig
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 6600K @ 4.7 GHz ASUS Z170 Pro Gaming AMD Sapphire Fury Nitro Crucial Ballistix Sport 8GB DDR4 
Hard DriveHard DriveCoolingCooling
Samsung 840 Series 120GB Solid State Drive  6TB Western Digital Blue Corsair H105 Hydro Series Antec 120mm Tricool fan (pinched from Antec 300... 
OSMonitorKeyboardPower
Windows 10 ViewSonic 23" IPS 2 ms monitor (VX2363SMHL-W) M... Ducky Shine 5 750 W StealthXStream (pinched from 2009 AMD rig) 
CaseMouse
Inwin 303 (White) Generic mouse 
  hide details  
The golden rig
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 6600K @ 4.7 GHz ASUS Z170 Pro Gaming AMD Sapphire Fury Nitro Crucial Ballistix Sport 8GB DDR4 
Hard DriveHard DriveCoolingCooling
Samsung 840 Series 120GB Solid State Drive  6TB Western Digital Blue Corsair H105 Hydro Series Antec 120mm Tricool fan (pinched from Antec 300... 
OSMonitorKeyboardPower
Windows 10 ViewSonic 23" IPS 2 ms monitor (VX2363SMHL-W) M... Ducky Shine 5 750 W StealthXStream (pinched from 2009 AMD rig) 
CaseMouse
Inwin 303 (White) Generic mouse 
  hide details  
post #113 of 306
I do have a bunch of packets lying around of programming challenges from MICS Programming Competition and some ACM ones. If anyone is interested let me know and I will post one. The MICS ones are a tad easier but still good fun.
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
post #114 of 306
Quote:
Originally Posted by Midpipps View Post
I do have a bunch of packets lying around of programming challenges from MICS Programming Competition and some ACM ones. If anyone is interested let me know and I will post one. The MICS ones are a tad easier but still good fun.
Post up son
post #115 of 306
Here is one that was deceptively simple sounding but gave us some trouble at the competition because darn if we could remember exactly how the last frame was scored and they would allow us no access to the internet to look it up.
We were required to make it with console input and output but make it as graphical or none graphical as you would like. Should be a good one for most any level of programmer.

MICs Programming Contest 2010
Bowling


History
Bowling has been traced to articles found in the tomb of an Egyptian child buried in 5200 BC. The primitive implements included nine pieces of stone at which a stone "ball" was rolled, the ball having first to roll through an archway made of three pieces of marble.
Another ancient discovery was the Polynesian game of ula maika, which also used pins and balls of stone. The stones were to be rolled at targets 60 feet away, a distance which is still one of the basic regulations of tenpins.
Bowling at tenpins probably originated in Germany, not as a sport but as a religious ceremony. Martin Luther is credited with settling on nine as the ideal number of pins.
Tracing history reveals the game moved through Europe, the Scandinavian countries and finally to the United States, where the earliest known reference to bowling at pins in America was made by author Washington Irving about 1818 in Rip Van Winkle.
Although the game was being played throughout the world, rules were different almost everywhere, and even basic equipment was not the same. In fact, why and when the 10th pin was added from the European game of ninepins to the American game of tenpins is still a mystery.
Rules
A single bowling game consists of ten frames. The object in each frame is to roll a ball at ten bowling pins arranged in an equilateral triangle and to knock down as many pins as possible.
For each frame, a bowler is allowed a maximum of two rolls to knock down all ten pins. If the bowler knocks them all down on the first attempt, the frame is scored as a strike. If the bowler does not knock them down on the first attempt in the frame the bowler is allowed a second attempt to knock down the remaining pins. If the bowler succeeds in knocking the rest of the pins down in the second attempt, the frame is scored as a spare.
The score for a bowling game consists of sum of the scores for each frame. The score for each frame is the total number of pins knocked down in the frame, plus bonuses for strikes and spares. In particular, if a bowler scores a strike in a particular frame, the score for that frame is ten plus the sum of the next two rolls. If a bowler scores a spare in a particular frame, the score for that frame is ten plus the score of the next roll. If a bowler scores a strike in the tenth (final) frame, the bowler is allowed two more rolls. Similarly, a bowler scoring a spare in the tenth frame is allowed one more roll.
The maximum possible score in a game of bowling (strikes in all ten frames plus two extra strikes for the tenth frame strike) is 300.
Input
The input will consist of a sequence of bowling game scores. Each line will contain the scores for a single game, with the scores for each roll of the ball separated by a single space. The score for a single roll will be represented by a single character -- either a number indicating the number of pins knocked down, a '/' for a spare or a 'X' for a strike.
The end of input is indicated by a single line containing the text Done (terminated with a newline).
Output
Your program should output the total game score for each game in the input file. The game scores should be left justified and each score should be printed on a separate line. The order of the scores on the output should correspond to the order of the games on the input.
Sample Input
4 3 6 2 1 3 4 2 7 1 1 0 2 3 4 5 8 0 5 2
1 0 1 / 2 2 X 3 3 X 1 / 3 / X 1 2
1 0 1 / 2 2 X 3 3 X 1 / 3 / 1 / 8 / 9
Done
Output for the Sample Input
63
108
120

Was thinking about a week for this one to be up and done will post another next week unless someone else wants to post one. 7/21/2010 End Date
Edited by Midpipps - 7/14/10 at 10:45am
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
post #116 of 306
Here is a scala implementation.

Code:
class Frame(aOne:String, aTwo:String) {                                         
 
def frameTyp:String = {
if(one==10) return "strike"; 
if(one + two == 10) return "spare"; 
return "normal";
}
var one:Int = aOne.toInt;
var two:Int = if(aTwo.equals("/")) 10 - one; else aTwo.toInt

var nextFrame:Frame = null;
//too lazy to do a bunch of null checks
def getNextFrame():Frame = { if(nextFrame == null) return new Frame("0","0"); return nextFrame;}

 def nextTwo(): Int = {
getNextFrame.frameTyp match {
  case "strike" => getNextFrame.one + getNextFrame.getNextFrame.one
                          case _        => getNextFrame.one + getNextFrame.two
}
           }
 def score():Int = { 
                   var a = frameTyp match {
                      case "strike" => 10 + nextTwo()
                      case "spare" => 10 + getNextFrame.one
                      case "normal" => one + two;
}
return a;
}

override def toString():String = { "(" + one + "," + two + ") =>" + score}
}

def totalFrames(inpList:String)
{
//replace X's with 10 0
var frameList = List.fromString(inpList.replace("X", "10 0"), ' ')

//if odd number of times bowled, add empty one 
if(frameList.size %2 == 1) frameList = frameList ::: List("0")
frameList = frameList.reverse
var operationList:List[Frame] = List[Frame]()

//store the "next" frame 
var currFrame:Frame = null

//every frame is two turns now
//doing this in reverse so that we always have the next frame handy
while(frameList.size > 0)
{
        //get first two items in list
var a = frameList.take(2);

        //1,0 due to reverse
val tempFrame = new Frame(a(1), a(0))
tempFrame.nextFrame=currFrame

        //get remaining frames
        frameList=frameList.drop(2);
        //always adding to the front of the list, so this list ends up in the proper order
operationList = tempFrame::operationList 
currFrame=tempFrame

}

//fancy way to sum
var total = operationList.map(x => x.score).foldLeft(0)(_ + _)

//apparently i didn't understand how bowling worked forever
//don't count the last two if beyond the 10'th frame except for scoring in 9th + 10th frames
if(operationList.size > 10) { total = total - operationList.drop(10).map(x => x.score).foldLeft(0)(_ + _) }
println(total)
}

//abuses memory
scala.io.Source.fromFile("sample.txt").getLines.mkString.lines.foreach{i => println(i); totalFrames(i)}
4 3 6 2 1 3 4 2 7 1 1 0 2 3 4 5 8 0 5 2
63
1 0 1 / 2 2 X 3 3 X 1 / 3 / X 1 2
108
1 0 1 / 2 2 X 3 3 X 1 / 3 / 1 / 8 / 9
120
Edited by impatient - 7/14/10 at 1:29pm
post #117 of 306
Will give it a go tomorrow evening after I finish some unit tests on some new stuff for work.
post #118 of 306
good call not to do it at work... i had to spend an evening catching up
post #119 of 306
OK I did a really quick one just for fun it is horribly programmed and definitely not what anyone would call good but it works.

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Bowling
{
    public partial class frmBowling : Form
    {
        private TextReader fileReader;
        public frmBowling()
        {
            InitializeComponent();
        }

        private void frmBowling_Load(object sender, EventArgs e)
        {
            fileReader = new StreamReader("sample.txt");
           
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            if (!(fileReader.Peek() == -1))
            {
                String[] gameString = fileReader.ReadLine().Split(' ');
                //I know this is a crappy way of doing this but don't really care it works 
                //and I don't want to take the time to position all those darned textboxes
                TextBox[] pins = new TextBox[] {txtpins1_1, txtpins1_2, txtpins2_1, txtpins2_2, 
                    txtpins3_1, txtpins3_2, txtpins4_1,   txtpins4_2, txtpins5_1, txtpins5_2, txtpins6_1,
                    txtpins6_2, txtpins7_1, txtpins7_2, txtpins8_1, txtpins8_2, txtpins9_1, txtpins9_2,
                    txtpins10_1, txtpins10_2, txtpins10_3};
                for (int i = 0; i < pins.Length; i++)
                    pins[i].Text = "";

                /*Put the pin counts into the upper textboxes sort of like the standard bowling sheet*/
                int count = 0;
                int frame = 0;
                for (int i = 0; i < gameString.Length; i += 1)
                {
                    if (gameString[i].ToLower().Contains('x'))
                    {
                        pins[count].Text = gameString[i];
                        if (frame != 10)
                            frame += 1;
                        if (frame == 10)
                            count += 1;
                        else
                        {
                            count += 2;
                        }
                    }
                    else
                    {
                        pins[count].Text = gameString[i];
                        count++;
                        if (count % 2 == 0 && frame != 10)
                        {
                            frame += 1;
                        }
                    }
                }

                /*Yep Being lazy again gonna make it one long program :)*/
                TextBox[] scores = new TextBox[] {txtScore1, txtScore2,txtScore3,txtScore4,
                    txtScore5,txtScore6,txtScore7,txtScore8,txtScore9,txtScore10};
                count = 0;
                frame = 0;
                int currentScore = 0;
                for (int i = 0; i < scores.Length; i++)
                    scores[i].Text = "";

                for (int i = 0; i < scores.Length; i += 1)
                {
                    frame++;
                    if (frame == 10)
                    {
                        if (pins[18].Text.ToLower().Contains('x'))
                            currentScore += 10;
                        else if (pins[18].Text.ToLower().Contains('/'))
                            currentScore += 10;
                        else if (pins[18].Text.Length > 0  && !(pins[19].Text.ToLower().Contains('/')))
                            currentScore += int.Parse(pins[18].Text);

                        if (pins[19].Text.ToLower().Contains('x'))
                            currentScore += 10;
                        else if (pins[19].Text.ToLower().Contains('/'))
                            currentScore += 10;
                        else if (pins[19].Text.Length > 0)
                            currentScore += int.Parse(pins[19].Text);

                        if (pins[20].Text.ToLower().Contains('x'))
                            currentScore += 10;
                        else if (pins[20].Text.ToLower().Contains('/'))
                            currentScore += 10;
                        else if (pins[20].Text.Length > 0)
                            currentScore += int.Parse(pins[20].Text);
                    }
                    else
                    {
                        if (pins[i * 2].Text.Length > 0)
                        {
                            if (pins[i * 2].Text.ToLower().Contains('x'))
                            {
                                currentScore += 10;
                                if (pins[(i * 2) + 2].Text.ToLower().Contains('x'))
                                {
                                    currentScore += 10;
                                    if (pins[(i * 2) + 4].Text.ToLower().Contains('x'))
                                        currentScore += 10;
                                    else
                                    {
                                        currentScore += int.Parse(pins[(i * 2) + 4].Text);
                                    }
                                }
                                else if (pins[(i * 2) + 3].Text.ToLower().Contains('/'))
                                    currentScore += 10;
                                else
                                {
                                    currentScore += int.Parse(pins[(i * 2) + 2].Text);
                                    currentScore += int.Parse(pins[(i * 2) + 3].Text);
                                }
                            }
                            else if (pins[(i * 2) + 1].Text.ToLower().Contains('/'))
                            {
                                currentScore += 10;
                                if (pins[(i * 2) + 2].Text.ToLower().Contains('x'))
                                    currentScore += 10;
                                else
                                    currentScore += int.Parse(pins[(i * 2) + 2].Text);
                            }
                            else
                                currentScore += int.Parse(pins[i * 2].Text) + int.Parse(pins[(i * 2) + 1].Text);

                        }
                    }
                    scores[i].Text = "\
\
\
\
" + currentScore.ToString();

                }

            }
            else
            {
                MessageBox.Show("There are no more score sorry", "ERROR", MessageBoxButtons.OK);
                this.Close();
            }
        }

        
        
    }
}
the sample.txt
Code:
4 3 6 2 1 3 4 2 7 1 1 0 2 3 4 5 8 0 5 2
1 0 1 / 2 2 X 3 3 X 1 / 3 / X 1 2
1 0 1 / 2 2 X 3 3 X 1 / 3 / 1 / 8 / 9
4 3 6 2 1 3 4 2 7 1 1 0 2 3 4 5 8 0 5 2
1 0 1 / 2 2 X 3 3 X 1 / 3 / X 1 2
1 0 1 / 2 2 X 3 3 X 1 / 3 / 1 / 8 / 9
1 0 1 / 2 2 X 3 3 X 1 / 3 / 1 / X 8 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
X X X X X X X X X X X X
and a screenshot for you all

    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
    
CPUMotherboardGraphicsRAM
Q6600 DG33TL XFX 6950 2GB 4gigs Corsair XMS2 DDR2 
Hard DriveOptical DriveOSMonitor
1.5TB seagate 2X640GB Samsung DVDRW Windows Vista & Debian Linux Samsung 19" + Acer 24" Wide 
KeyboardPowerCaseMouse
Microsoft SideWinder X6 Antec 750 TruePower Raidmax Smilodon COOLER MASTER Sentinel 
Mouse Pad
RocketFish 
  hide details  
post #120 of 306
Code:
#include <iostream>
#include <string>
using namespace std;
struct frame{ int t1,t2,s; };
int main(int argc, char** argv)
{
int total = 0, i = 0;
frame score[10];
string c = argv[1];
for(int f = 0; f<10; f++){
if(c[i] == 'X' && f != 9)   score[f] = {10,-1,-i++};
else if (c[i] == 'X' && f == 9){   
  score[f].t1 = 10;
  if(c[i+1] == 'X') score[f].t2 = 10;
  else    score[f].t2 = c[i+1] - '0';
  if(c[i+2] == 'X' || c[i+2] == '/') score[f].t2 +=10;
  else    score[f].t2 +=c[i+2] - '0';
  score[f].s = score[f].t1 + score[f].t2;
}else if (c[i+1] == '/' && f!=9)   score[f] = {c[i++]-'0',10,-i++};
else if (c[i+1] == '/' && f==9)   score[f] = {c[i]-'0', 10, 10+c[i+2]-'0'};
else       score[f] = {c[i]-'0',c[i+1]-'0',c[i++]-'0' + c[i++]-'0'};
}
for(int f = 9; f>=0; f--){
if(score[f].s <= 0){
if(score[f].t1 == 10){
if(score[f+1].t1 == 10 && f != 8) score[f].s = 20 + score[f+2].t1;
else if(score[f+1].t1 == 10 && f == 8) score[f].s = 10 + score[f+1].t2;
else if(score[f+1].t2 == 10) score[f].s = 20;
elsescore[f].s = 10 + score[f+1].t1 + score[f+1].t2;
}else if(score[f].t2 == 10) score[f].s = 10 + score[f+1].t1;
}
total += score[f].s;
}
cout << "Total is " << total << endl;
}
Managed to get it down to 35 lines (without making it completely unreadable).

It should be less, but there are too many special conditions to handle.





I deviated a little from the format, but its really only a couple of extra lines of string parsing to get it to comply with the spec.
    
CPUMotherboardGraphicsRAM
Core i5 4670k ASUS Maximus VI Gene Gigabyte GTX 460 1GB Kingston Hyper-X 
Hard DriveHard DriveHard DriveHard Drive
Samsung 830 OCZ Vertex 3 WD6401AALS WD5000AAKS 
CoolingOSMonitorMonitor
Noctua NH-D14 elementary OS Dell Ultrasharp U2312HM LG W2442PA-BF 
KeyboardPowerCaseMouse
Microsoft Sidewinder X4 Corsair HX750W Corsair Graphite 600T Logitech G700 
Audio
ASUS Xonar DG 
  hide details  
    
CPUMotherboardGraphicsRAM
Core i5 4670k ASUS Maximus VI Gene Gigabyte GTX 460 1GB Kingston Hyper-X 
Hard DriveHard DriveHard DriveHard Drive
Samsung 830 OCZ Vertex 3 WD6401AALS WD5000AAKS 
CoolingOSMonitorMonitor
Noctua NH-D14 elementary OS Dell Ultrasharp U2312HM LG W2442PA-BF 
KeyboardPowerCaseMouse
Microsoft Sidewinder X4 Corsair HX750W Corsair Graphite 600T Logitech G700 
Audio
ASUS Xonar DG 
  hide details  
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
This thread is locked  
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programming Challenge (Out-of-Date)