Guest User

Untitled

a guest
Feb 7th, 2014
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. int pljuniId(int* nums, int cnt) {
  6.     int i;
  7.  
  8.     int max = nums[0] % 10, maxId = 0;  //pretpostavljamo
  9.     int cif;
  10.  
  11.     for ( i = 0; i < cnt; i ++ ) {  //idemo broj po broj.
  12.         while ( nums[i] != 0 ) {  //idemo cifru po cifru.
  13.             cif = nums[i] % 10;
  14.             if ( cif > max ) {
  15.                     max = cif;
  16.                     maxId = i;
  17.             }
  18.             else if ( cif == max ) {
  19.                 while ( (nums[maxId] % 10) == (nums[i] % 10) ) {
  20.                     nums[maxId] /= 10;
  21.                     nums[i] /= 10;
  22.  
  23.                     if ( nums[i] == 0 ) break;
  24.                 }
  25.  
  26.             }
  27.             nums[i] /= 10;
  28.         }
  29.     }
  30.  
  31.     return maxId;
  32. }
  33.  
  34. int main()
  35. {
  36.     int nums[10] = {123, 321, 12, 325, 125, 57, 5125, 1252, 12521, 12552};
  37.  
  38.     printf("%d", pljuniId(nums, 10));
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment