SPOJ GENERAL: sorting by swaps of distance k
The above code can be optimized a little by below changes.

Replace this

        for( ; j &lt; i - k; j++) {
            if(a[j] &gt; a[j + k]) {
                int temp = a[j];
                a[j] = a[j + k];
                a[j + k] = temp;
                count++;
            }
        }

        for( ; j &lt; i - 1; j++) {
            if(a[j] &gt; a[j + 1]) {
                result = false;
                break;
            }
        }

        if(!result)
            break;


By 

        int  j = i-k;
        int x = 0;
        int tmp[i/k]; // Do check for i==0 here 
        for(int j = i; j &gt;= 0; j -= k){
            tmp[x] = a[j];  
            x++;
        }
        sort(tmp);
        for(int j = i; j &gt;= 0; j -= k){
             a[j] = tmp[x]; x--; 
        }


Add a check outside the main loop if its sorted or not. 
But still this will be in order of \$O(N*KlogK)\$ which in worst cases \$O(N^2logN)\$. You might still get the TLE with that. 

We can solve this in \$O(NlogN)\$. Trying thinking of solution in which you sort this a keeping original indexes of each element. Then calculate the number of swap by comparing the old index with new one.