Skip to content

Instantly share code, notes, and snippets.

@jnozsc
Created September 30, 2011 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnozsc/1253470 to your computer and use it in GitHub Desktop.
Save jnozsc/1253470 to your computer and use it in GitHub Desktop.
draft for piptu question
new array a[10]; // input
new array b[10]={0,0,0,0,0,0,0,0,0,0};
bool flag = true;
int c = 0;
while(flag){
flag = false;
int i;
// loop
for(i=0,i<10,i++){
int c = countNumber(b,a[i]);
// if b[i] is incorrect
if(b[i]!=c) {
b[i]=c;
// need set flag to true to continue the next loop to verify the b[].if flag is false, b[] is correct.
flag= true;
}
}
}
// count the number of b in the given array
int countNumber(array[] a, int b){
int i=0;int j;
for(j=0, j<a.length, j++){
if(a[j]==b)i++
}
return i;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment