Advertisement
Aslai

Untitled

Feb 18th, 2012
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. struct t{
  5.     int carry;
  6.     int times;
  7. };
  8. int getfirst(int a){
  9.     return a - a / 10 * 10;
  10. }
  11. int main(){
  12.     char in[1000];
  13.     struct t list[] = { {0,0}, {20,3}, {40,6}, {60,9}, {10,2}, {30,5}, {50,8}, {0,1}, {20,4}, {40,7} };
  14.     int save[4];
  15.     printf("Target: ");
  16.     gets(in);
  17.     int target = strtol( in, 0, 10 );
  18.     int j, i;
  19.     for( i = 3; i >= 0; --i ){
  20.         j = getfirst( target );
  21.         save[i] = list[j].times;
  22.         target -= list[j].carry;
  23.         target /= 10;
  24.     }
  25.     for( i = 0; i < 4; ++i ){
  26.         printf("%i", save[i]);
  27.         if( i < 3 )
  28.             printf(">");
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement