Created
September 30, 2011 11:21
-
-
Save jnozsc/1253470 to your computer and use it in GitHub Desktop.
draft for piptu question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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