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 31  

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 #301 of 306
I was trying to implement HashMap but wasn't getting anywhere (didn't use <Integer, Integer> when I declared the Map). Found this page though, even though it uses Hashtables instead it's pretty much the same thing. Props to that guy for making this work lol
Code:
import static java.lang.System.out;
import static java.lang.System.in;
import java.util.*;

public class StampCalc {
    public static HashMap<Integer, Integer> hash = new HashMap<Integer, Integer>();
    public static void main(String[] args) {
        
        Scanner kb = new Scanner(in);Scanner intkb = new Scanner(in);
        int i=0;
        out.print("Input available number of stamp denominations: ");
        int start = kb.nextInt(); kb.nextLine();
        out.print("Input stamp values serparated by spaces: ");
        String temp = kb.nextLine();
        int[] stampArray = new int[start]; 
        int[] amountArray;
        StringTokenizer sA = new StringTokenizer(temp);
        while (sA.hasMoreTokens())
        {
            stampArray[i] = Integer.parseInt(sA.nextToken());
            i++;
        }
        Arrays.sort(stampArray);
        
        ArrayList stampAmount = new ArrayList();
        out.print("Input postage amount, or enter 0 to finish: ");
        for( ; ; )
        {
            int chk = intkb.nextInt();
            if (chk == 0){
                amountArray = new int[stampAmount.size()];
                for (int p=0; p<stampAmount.size(); p++) amountArray[p] = (int)stampAmount.get(p);
                break;
            }
            stampAmount.add(chk);
            out.print("Next?: ");
        }
        
        for(int y = 0;y<amountArray.length;y++){
        int minimum = dynTable(stampArray, amountArray[y]);
        out.print("Case ");out.print(y+1);out.print(": The postage amount ");out.print(amountArray[y]);out.print(" can be made using ");out.print(minimum);out.println(" stamps");
        }
    }
    
    public static int dynTable(int[] stampValue, int postAmount){
        if (postAmount <=0) return postAmount;
        int min = -1; 
        for (int z =0; z <= stampValue.length - 1; z++) 
        {
            int updateAmount = postAmount - stampValue[z];
            int stampCount=0;
            if (hash.get(updateAmount) != null) {
                stampCount = hash.get(updateAmount) + 1;
            } 
            else {
                stampCount = dynTable(stampValue, updateAmount);
                if (stampCount >= 0) stampCount++;
            }
            if ((stampCount > 0) && (min == -1 || stampCount < min)) {
                min = stampCount;
            }
        }
        hash.put(postAmount, min);
        return min;
    }
}
Blitzkrieg
(14 items)
 
  
CPUMotherboardGraphicsRAM
i7 980X Asus P6X58D Premium GTX 680 G.Skill 6Gb 2000Mhz 
Hard DriveOptical DriveCoolingOS
OCZ Vertex 3 BD/DVD Combo EK Supreme HF Windows 7 
MonitorKeyboardPowerCase
SAMSUNG S27A850T 27" Microsoft basic 600 :p AeroCool V12 1000W HAF 932 
Mouse
Razer Deathadder V2 
  hide details  
Blitzkrieg
(14 items)
 
  
CPUMotherboardGraphicsRAM
i7 980X Asus P6X58D Premium GTX 680 G.Skill 6Gb 2000Mhz 
Hard DriveOptical DriveCoolingOS
OCZ Vertex 3 BD/DVD Combo EK Supreme HF Windows 7 
MonitorKeyboardPowerCase
SAMSUNG S27A850T 27" Microsoft basic 600 :p AeroCool V12 1000W HAF 932 
Mouse
Razer Deathadder V2 
  hide details  
post #302 of 306
Here is the next one

Quote:

Problem 1 — 15-Tile Puzzle

Professor Smith’s favorite puzzle as a child is the 15-tile puzzle in which 15 tiles and one blank space occupy a 4x4 grid. Tiles adjacent to the blank space horizontally or vertically can be slid into the blank space. The goal is to move the tiles around so that the numbers 1-15 are arranged numerically left to right and top to bottom with the blank space in the lower right corner. Not all initial arrangements result in a valid solution. In fact, exactly half of them do! Any arrangement may be moved to either the solution position or a “near solution†position in which the 14 and 15 tiles are reversed. Given an initial arrangement of tiles, you are to determine whether the puzzle can be solved from that position.

INPUT SPECIFICATION: You will be given a set of input cases, each of which will be a
16-character string followed by <EOLN>. The last input case will be followed by an extra <EOLN>.
Each input string will consist of 1-9, A-F (representing 10-15) and an asterisk, ‘*’ (representing the blank space). Each of these characters will appear in the string exactly once, but they could appear in any order. This string represents a initial position in the 4x4 grid, with the first 4 characters representing the first row, the second 4 characters representing the second row, and so forth.

OUTPUT SPECIFICATION: The output cases should appear in the same order as the input cases. Each output case will be either “Case c: YES†or “Case c: NO†(where c is the case number) depending on whether the grid can be solved. <EOLN> follows each output case.

SAMPLE INPUT:
123456789ABCDEF*<EOLN>
123456789ABCDFE*<EOLN>
*123456789ABCDEF<EOLN>
<EOLN>
<EOF>

SAMPLE OUTPUT:
Case•1:•YES<EOLN>
Case•2:•NO<EOLN>
Case•3:•NO<EOLN>
<EOF>
    
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 #303 of 306
Code:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;


int main ()
{
ofstream yourfile;
ifstream myfile;
string str;
int sum=0,cas=0,blank=0;
yourfile.open("prob1out.txt");
myfile.open("prob1.txt");
while(!myfile.eof())
{
cas++;
getline (myfile,str);
if(!str.empty())
{
for(int i = 0;i<str.length();i++)
{
if(str[i] != '*')
{
for(int x=i;x<str.length();x++)
{
if(str[x] != '*')
if((int)str[i] > (int)str[x]) sum++;
}
}
else blank = i;
}
blank = ceil((double)blank/4);
cout << blank << endl;
if(sum%2 == 0 && blank%2 != 0 || sum%2 != 0 && blank%2 == 0)
yourfile << "Case " << cas << ": YES" << " dot is in " << blank << "number is " << sum << endl;
else
yourfile << "Case " << cas << ": NO" << " dot is in " << blank << "number is " << sum << endl;
sum = 0;
}
}
myfile.close();
yourfile.close();
getchar();
    return 0;
}
here's an explanation how to solve this : http://www.cs.bham.ac.uk/~mdr/teachi...lvability.html

count inversions -> if the number is even the empty square has to be on an odd line or the opposite if the number's odd.
but that doesn't seem to comply with the given answers so i'm lost
Pepe Silvia
(13 items)
 
  
CPUMotherboardGraphicsRAM
255 @ 4 Ghz MSI 870-C45 GT 520 @ 1Ghz Crucial Rendition 4GB DDR3 
Hard DriveOSMonitorPower
Hitachi 1TB Win 7 19" 420W 
  hide details  
Pepe Silvia
(13 items)
 
  
CPUMotherboardGraphicsRAM
255 @ 4 Ghz MSI 870-C45 GT 520 @ 1Ghz Crucial Rendition 4GB DDR3 
Hard DriveOSMonitorPower
Hitachi 1TB Win 7 19" 420W 
  hide details  
post #304 of 306
It's been a while since any programming challenges were posted here. Midpips was the last person providing the challenges but it appears that he hasn't logged in in months.

I intend to update this thread with new challenges and anyone who wishes to contribute is welcome to PM me or post here.
In fact, I'd really appreciate your help guys.
Maybe we can discuss a way to organise this by dividing the responsibility of managing the challenges between members who are willing to help.

However, when I come to think of it, there is no point of this thread if no one is willing to participate as simply posting programming tasks will be pretty useless. I will put up a poll now to see how many people are interested in this kicking off again. Otherwise, I'll have to let this go.

smile.gif

~ {Unregistered}
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  
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  
post #305 of 306
You should make a new thread. It isn't obvious that people should go to the last post.
Akiyama Mio
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6420 @ stock, 0.98v Asus P5N-E SLI Gainward GTX 460 1GB @ 800/1600/1900 2x2GB Kingston @ 800MHz 5-5-5-15 2T 
Hard DriveOptical DriveOSMonitor
WD 250GB, 320GB SATA/3, 16MB Cache, Seagate 1TB LG GSA-H62N 18x SATA Ubuntu 9.10 x86 & Win7 x86 Asus VW222U 
KeyboardPowerCase
Logitech Classic Corsair 650HX NZXT Apollo Black 
  hide details  
Akiyama Mio
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6420 @ stock, 0.98v Asus P5N-E SLI Gainward GTX 460 1GB @ 800/1600/1900 2x2GB Kingston @ 800MHz 5-5-5-15 2T 
Hard DriveOptical DriveOSMonitor
WD 250GB, 320GB SATA/3, 16MB Cache, Seagate 1TB LG GSA-H62N 18x SATA Ubuntu 9.10 x86 & Win7 x86 Asus VW222U 
KeyboardPowerCase
Logitech Classic Corsair 650HX NZXT Apollo Black 
  hide details  
post #306 of 306
Quote:
Originally Posted by Coma View Post

You should make a new thread. It isn't obvious that people should go to the last post.

Thank you for the suggestion. Done and locked (until ever needed)!
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  
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  
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)