SHOW:
|
|
- or go back to the newest paste.
| 1 | - | #include <stdio.h> |
| 1 | + | using System; |
| 2 | - | int main(){
|
| 2 | + | using System.Collections.Generic; |
| 3 | - | char in[1000]; |
| 3 | + | using System.Linq; |
| 4 | - | struct{int carry;int times;} list[] = { {0,0}, {20,3}, {40,6}, {60,9}, {10,2}, {30,5}, {50,8}, {0,1}, {20,4}, {40,7} };
|
| 4 | + | using System.Text; |
| 5 | - | printf("Target: ");
|
| 5 | + | |
| 6 | - | gets(in); |
| 6 | + | namespace PuzzleSolver{
|
| 7 | - | int target = strtol( in, 0, 10 ), j, i,save[4]; |
| 7 | + | class program{
|
| 8 | - | for( i = 3; i >= 0; --i ){
|
| 8 | + | struct t{
|
| 9 | - | j = target - target / 10 * 10; |
| 9 | + | public int carry, times; |
| 10 | - | save[i] = list[j].times; |
| 10 | + | public t( int c, int t ){
|
| 11 | - | target = ( target - list[j].carry ) / 10; |
| 11 | + | carry = c; times = t; |
| 12 | } | |
| 13 | - | for( i = 0; i < 4; ++i ) |
| 13 | + | }; |
| 14 | - | printf("%i%c", save[i], i < 3 ? '>' : ' ' );
|
| 14 | + | static void Main( string[] args ){
|
| 15 | t[] list = { new t(0,0), new t(20,3), new t(40,6), new t(60,9), new t(10,2), new t(30,5), new t(50,8), new t(0,1), new t(20,4), new t(40,7) };
| |
| 16 | Console.Write("Target: ");
| |
| 17 | String inp = Console.ReadLine(); | |
| 18 | int target = Convert.ToInt32( inp ); | |
| 19 | int j, i; | |
| 20 | int[] save = new int[4]; | |
| 21 | for( i = 3; i >= 0; --i ){
| |
| 22 | j = target - target / 10 * 10; | |
| 23 | save[i] = list[j].times; | |
| 24 | target = ( target - list[j].carry ) / 10; | |
| 25 | } | |
| 26 | for( i = 0; i < 4; ++i ) | |
| 27 | Console.Write("{0}{1}", save[i], i < 3 ? '>' : ' ' );
| |
| 28 | Console.ReadLine(); | |
| 29 | } | |
| 30 | } | |
| 31 | } |