Giter Site home page Giter Site logo

paintshop_exercise's Introduction

You run a paint shop, and there are a few different colors of paint you can prepare. Each color can be either "glossy" or "matte".

You have a number of customers, and each have some colors they like, either glossy or matte. No customer will like more than one color in matte.

You want to mix the colors, so that:

  • There is just one batch for each color, and it's either glossy or matte.
  • For each customer, there is at least one color they like.
  • You make as few mattes as possible (because they are more expensive).

Your program should accept an input file as a command line argument, and print a result to standard out. An example input file is:

5
1 M 3 G 5 G
2 G 3 M 4 G
5 M

The first line specifies how many colors there are.

Each subsequent line describes a customer. For example, the first customer likes color 1 in matte, color 3 in glossy and color 5 in glossy.

Your program should read an input file like this, and print out either that it is impossible to satisfy all the customer, or describe, for each of the colors, whether it should be made glossy or matte.

The output for the above file should be:

G G G G M

...because all customers can be made happy by every paint being prepared as glossy except number 5.

An example of a file which has no solution is:

1
1 G
1 M

Your program should print

No solution exists

A slightly richer example is:

5
2 M
5 G
1 G
5 G 1 G 4 M
3 G
5 G
3 G 5 G 1 G
3 G
2 M
5 G 1 G
2 M
5 G
4 M
5 G 4 M

...which should print:

G M G M G

One more example. The input:

2
1 G 2 M
1 M

...should produce

M M

paintshop_exercise's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.