Replace the Indexes without Loop - java

My Question is :
First I have String variable of 1000 character, and I have another set of String variable of 1000 character
1] In First Set of Variable contains "1110000XXXXX0001111...." like this and so on, till 1000
2] In The second Set of Variable contains "1110000101010001111..." like this and so on till 1000
3] I need to get the position of X in first Variable and replace the Value of similar position from the second variable
For ex : 1st Variable of data "000XXX000X0"
2nd Variable of data "00011000010"
The X should be replaced by the values which is in the position in 2nd set of data.
NOTE : TO BE DONE WITHOUT LOOP
because if we put loop its runs 1000 times in a loop and 'X' may be anywhere in 1000 characters in the String
For ex: 1 Record 1000 Times
if 100K Records means 1000*100K (PERFORMANCE FAILS)
So need solution for it.
Kindly Help me out with this.
My Code is :
String sInputStr="0X11XXXXX000000000000000000000000000000000000000000000000X000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011";
String sDbStr="0111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011";
int iLength=sInputStr.length();
for(int i=0;i<iLength;i++){
if(sInputStr.charAt(i)=='X'){
}else{
if(i>sDbStr.length()){
break;
}else{
sChar[i] = sInputStr.charAt(i);
}
}
}//End of For
sVal=String.valueOf(sChar);
System.out.println("sVal == " +sVal);
Help Me friends

All you need is something like this
class FirstApp {
public static void main(String[] args) {
String sDbStr="0111111110000001234000000000000011";
StringBuilder sNewStr= new StringBuilder("011111111000000XXXX00000000000001112");
String findStr = "X";
int lastIndex = 0;
System.out.println("Starting");
long startTime = System.currentTimeMillis();
String result = replaceValues("X", sDbStr, sNewStr);
long endTime = System.currentTimeMillis();
System.out.println("Result");
System.out.println(result);
System.out.println(String.valueOf(endTime-startTime));
}
public static String replaceValues(String toReplace, String fromStr, StringBuilder toStr) {
int lastIndex = toStr.indexOf(toReplace);
if(lastIndex != -1){
toStr.replace(lastIndex,lastIndex+1,Character.toString(fromStr.charAt(lastIndex)));
System.out.println(toStr);
return replaceValues(toReplace, fromStr, toStr);
} else {
return toStr.toString();
}
}
}
sample result:
Starting
0111111110000001XXX00000000000001112
01111111100000012XX00000000000001112
011111111000000123X00000000000001112
011111111000000123400000000000001112
Result
011111111000000123400000000000001112
UPDATE Updated solution to ensure less execution time using stringBuilder and recursion

If X point to one value, like as mentioned X replace by 1. Go for string.replaceAll function.
ie.
String oriString="000XXX000X0";
String replaceOne=oriString.replace('X','1');
System.out.println(replaceOne);

If I understood the problem correctly then you want to replace the values of X in your first array with the values from seconds array at the same positions. For Example, array1: 000XXX000 & array2: 100101001. Then array1 should finally be 000101000.
Here is a simple code snippet to achieve this:
char[] arr1 = sInputStr.toCharArray();
char[] arr2 = sDbStr.toCharArray();
for(int i = 0; i < arr1.size(); i++)
if(arr1[i] == 'X')
arr1[i] == arr2[i];

The idea is to search for the index of the occurrence of the character say 'X' and copy all the characters from second string into the first as long as we find 'X'. Repeat the process till the last occurrence of 'X'.
public class Test
{
public static void main(String args[])
{
String s1 = "0X11XXXXX000000000000000000000000000000000000000000000000X000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011";
String s2= "0111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011";
char a[] = s1.toCharArray();
int i = s1.indexOf('X', 0);
while(i!=-1)
{
while(a[i] == 'X'){
a[i] = s2.charAt(i);
i++;
}
i = s1.indexOf('X',i+1);
}
s1 = new String(a);
System.out.println("result: "+s1);
}
}

Related

Count the numbers of numeric value in a given string

Java program to accept a string and count total numeric values.
public class Test2{
public static void main(String[] args){
String str = "I was 2 years old in 2002";
int count = 0, i;
for(i = 0; i < str.length(); i++){
if(str.charAt(i) >= 48 && str.charAt(i) <= 57){
count++;
// while(str.charAt(i) >= 48 && str.charAt(i) <= 57)
// i++;
}
}
System.out.println("Output: " +count);
}
}
Output = 5
After uncommenting the two lines written inside while loop -
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 25
at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:48)
at java.base/java.lang.String.charAt(String.java:712)
at Test2.main(Test2.java:9)
The output should be 2, because there are two numeric values - 2 and 2002
I have commented on the two lines in the above code, after uncommenting the code, the same logic works perfectly in C++.
An alternative to #DarkMatter´s answer using Pattern:
public static void main(String[] args) {
String str = "I was 2 years old in 2002";
long count = Pattern.compile("\\d+").matcher(str).results().count();
System.out.println(count);
}
You are checking individual charters so it counts every digit (as you probably realize). Java String has some nice tools to help you here. You could split the line into words and check each against a regular expression using String.matches():
String str = "I was 2 years old in 2002";
int count = 0;
for(String s : str.split(" ")) {
if(s.matches("[0-9]*")) {
count++;
}
}
System.out.println(count);
You can do the same thing (almost) with a stream:
String str = "I was 2 years old in 2002";
long count = Arrays.stream(str.split(" "))
.filter(s -> s.matches("[0-9]*")).count();
System.out.println(count);
In C, strings end in an ASCII NUL character (well, in basic C, strings don't exist, it's a library bolt-on, but most bolt-ons have NUL terminated strings). In java, that's not how it works.
The reason that your code is not working in java, but it is in C, is that you just keep going until you hit a non-digit character in that inner while loop. That means if the string ends in a digit (which yours does), your code asks the string: Give me the character at (one position beyond its length). In C that works; that's ASCII NUL, and thus your inner loop ends, as that's not a digit.
In java it doesn't, because you can't ask for a character beyond the end of a string.
You can 'fix' your code as pasted by also adding a check that i is still below length: if (i < str.length() && str.charAt(i).... ).
As the other answers showed you, there are more java idiomatic ways to solve this problem too, and probably the strategies shown in the other answers is what your average java coder would most likely do if faced with this problem. But there's nothing particularly wrong with your C-esque solution, once you add the 'check length' fix.
below code will input String from user and return the number of occurrences of numeric values as count.
import java.util.Scanner;
public class NumberCountingString
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String str = in.nextLine();
int count = 0, i;
int size = str.length(); // will only get size once instead of using in loop which will always get size before comparing
for(i = 0; i < size; i++)
{
if(Character.isDigit(str.charAt(i))) //if char is digit count++
{
count++;
for (int j = i; j < size; ) //inner loop to check if next characters are also digits
{
if(Character.isDigit(str.charAt(j))) // if yes skip next char
{
i++;
j=i;
}
else{ //break inner loop
break;
}
}
}
}
System.out.println("Output: " +count);
}
}
There are many options in Java as already shared by others. Below is very similar to your existing code and gives your desired output:
public static void main(String[] args) {
String str = "I was 2 years old in 2002";
String[] splittedString = str.split(" ");
int count = 0, i;
for (i = 0; i < splittedString.length; i++) {
if (StringUtils.isNumeric(splittedString[i])) {
count++;
}
}
System.out.println("Output: " + count);
}
You can split this string into an array of words, then filter those words where codePoints of the characters match digits, i. e. allMatch (Character::isDigit), and count these words:
String str = "I was 2 years old in 2002";
long count = Arrays
// split string into an array of words
.stream(str.split("\\s+"))
// for each word check the code points of the
// characters, whether they are digits or not.
.filter(w -> w.codePoints()
.mapToObj(ch -> (char) ch)
.allMatch(Character::isDigit))
.count();
System.out.println(count); // 2
See also: Transform String to byte then to int

How to iterate through large string with substrings incrementing by 1 position?

I have a String with an enormous number in it (thousands of chars):
String pi = "3.14159265358979323846264338327950288419716939937..."
I want to cycle through this string, grabbing 6 chars at a time, and checking if they match a given String:
String substring = "3.1415"
However, on each subsequent substring, I want to shift 1 position to the right of the chars in the original String:
substring = ".14159"
substring = "141592"
substring = "415926"
substring = "159265"
etc. etc.
What is the best way to do this? I have considered StringBuilder's methods, but converting to a String each iteration might be costly. String's method
substring(int beginIndex, int endIndex)
seems to approach what I'm trying to do, but I don't know if those indices can be incremented algorithmically.
I don't know if those indices can be incremented algorithmically.
These are parameters. They are values provided by you for each invocation of the method.
You are free to specify anything you want based on variables, constants, expressions, user input, or anything else. In this case, you can keep one or two variables, increment them, and pass them as parameters.
Here's an example using two variables that are both incremented by 1 each iteration:
class Main {
public static void main(String[] args) {
String pi = "3.14159265358979323846264338327950288419716939937...";
for(int start=0, end=6; end <= pi.length(); start++, end++) {
String substring = pi.substring(start, end);
System.out.println(substring);
}
}
}
Here's an algorithm that's efficient at matching values. Might be more efficient then using substring methods since it short circuits as soon as values don't match the provided sequence.
public static int containsSubstring(String wholeString, String findValue) {
//Break values into arrays
char[] wholeArray = wholeString.toCharArray();
char[] findArray = findValue.toCharArray();
//Use named outer loop for easy continuation to next character place
outerLoop:
for(int i = 0; i < wholeArray.length; i++) {
//Remaining values aren't large enough to contain find values so stop looking
if(i + findArray.length > wholeArray.length) {
break;
}
//Loop through next couple digits to check for matching sequence
for(int j = 0; j < findArray.length; j++) {
//Breaks loop as soon as a values don't match
if(wholeArray[i + j] != findArray[j]) {
continue outerLoop;
}
}
return i; //Or 'true' of you just care whether it's in there, and set the method return to boolean
}
return -1; //Or 'false'
}
Or java 8 style
String pi = "3.14159265358979323846264338327950288419716939937...";
IntStream.range(0, pi.length() - 5)
.mapToObj(i -> new StringBuffer(pi.substring(i, i + 6)))
.forEach(System.out::println)
;
You have the possibility to make it parallel
String pi = "3.14159265358979323846264338327950288419716939937...";
IntStream.range(0, pi.length() - 5)
.mapToObj(i -> new StringBuffer(pi.substring(i, i + 6)))
.parallel()
.forEach(System.out::println)
;
Speaking about performances the classic for loop method is still a little bit faster of it; you should do some tests:
public class Main {
static long firstTestTime;
static long withStreamTime;
static String pi = "3.141592653589793238462643383279502884197169399375105820974944592307816";
public static void main(String[] args) {
firstTest(pi);
withStreams(pi);
System.out.println("First Test: " + firstTestTime);
System.out.println("With Streams: " + withStreamTime);
}
static void withStreams(String pi) {
System.out.println("Starting stream test");
long startTime = System.currentTimeMillis();
IntStream.range(0, pi.length() - 5)
.mapToObj(i -> new StringBuffer(pi.substring(i, i + 6)))
//.parallel()
.forEach(System.out::println)
;
withStreamTime = System.currentTimeMillis() - startTime;
}
// By #that other guy
static void firstTest(String pi) {
System.out.println("Starting first test");
long startTime = System.currentTimeMillis();
for(int start=0, end=6; end <= pi.length(); start++, end++) {
String substring = pi.substring(start, end);
System.out.println(substring);
}
firstTestTime = System.currentTimeMillis() - startTime;
}
}
Try to increase the greek pi length!

Accessing index values before and after symbol from input

I am trying to take the input and if there is an # symbol in the input then it finds the maximum of the integers before and after the # symbol. The maximum part I have no problem with but I do not know how to access and find the values before and after the # symbol.
import java.util.Scanner;
public class Max_Min {
public static void main(String[] args) {
//gets keyboard
Scanner keyboard = new Scanner(System.in);
//puts input into string
String inputString = keyboard.nextLine();
//splits string between characters
String[] splitInput = inputString.split("");
for (String s : splitInput) {
if(s.equals("#")){
//computes the maximum of the two integers before and after the #
}
}
//close keyboard
keyboard.close();
I did do a search to find something simliar (and im sure there is something) but could not find anything. If someone could help that would be great!
Try with this:
for (int i = 0; i < splitInput.length; i++){
if (splitInput[i].equals("#") && i != 0 && i != splitInput.length -1){
int max = Math.max(Integer.parseInt(splitInput[i - 1]), Integer.parseInt(splitInput[i + 1]));
}
//...
}
You could try:
String[] splitInput = inputString.split("#");
which would split your string at the #s.
Then you can do a iteration over your splitInput array and do a .length on each index.
You have written the simple for loop, with which you can only access the string, but not its index in the array. If you had the index, you could write:
int possibleMax = Integer.parseInt(splitInput[i - 1]) + Integer.parseInt(splitInput[i + 1]);
To get the index, there are two ways:
for (int i = 0; i < splitInput.length; i++) {
String s = splitInput[i];
...
}
Or:
int i = 0;
for (String s : splitInput) {
…
i++;
}
I don't like either version because both are more complicated than absolutely necessary, in terms of written code. If you would use Kotlin instead of Java, it would be:
splitInput.forEachIndexed { i, s ->
…
}
In Java this could be written:
forEachIndexed(
splitInput,
(i, s) -> …
);
The problem in Java is that the code inside the … cannot update the variables of the enclosing method. I'm not sure whether this will ever change. It would be possible but needs a lot of work by the language committee.
A simple way to do this would be
String input = "12#23";
String [] arr = input.split("#");
if (arr.length == 2) {
System.out.println("Max is "+Math.max(Integer.valueOf(arr[0]),Integer.valueOf(arr[1])));
}

Having trouble with for loops

So, I need to write a program using loops that takes a string and counts what and how many letters appear in that string. (string "better butter" would print "b appears 2 times, e appears 3 times, ' '(space) appears 1 time, and so on). While I understand the idea and concept behind this assignment, actually pulling it off has been rough.
My nested for loop is where the problems are coming from, I assume. What I've written only loops once (i think) and just shows the first character and says there's only one of that character.
Edit: Preferably without using Map or arrays. I'm fine with using them if it's the only way, but they've not been covered in my class so I'm trying to avoid them. Every other similar question to this (that I've found) uses Map or array.
import java.util.Scanner;
class myString{
String s;
myString() {
s = "";
}
void setMyString(String s) {
this.s = s;
}
String getMyString() {
return s;
}
String countChar(String s){
s = s.toUpperCase();
int cnt = 0;
char c = s.charAt(cnt);
for (int i = 0; i <= s.length(); i++)
for (int j = 0; j <= s.length(); j++) //problem child here
c = s.charAt(cnt);
cnt++;
if (cnt == 1)
System.out.println(c+" appears "+cnt+" time in "+s);
else
System.out.println(c+" appears "+cnt+" times in "+s);
return "for"; //this is here to prevent complaint from the below end bracket.
}
}
public class RepeatedCharacters {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s;
System.out.println("Enter a sentence: ");
s = in.nextLine();
myString myS = new myString();
// System.out.println(myS.getMyString());
// System.out.println(myS.countChar());
myS.countChar(s);
}
}
First you will need to scan the entire string and store the
counts of each characters. Later you can just print the counts.
Algorithm 1:
Use a HashMap to store the character as key and its count as value. (If you are new to Java, you might want to read up on
HashMaps.)
Every time you read a character in your for loop, check if it present in the HashMap. If yes, then increment the count by 1. Else
add a new characters to the map with count 1.
Printing:
Just iterate on your HashMap and print out the character and
their respective counts.
Issue with your code: You are trying to print the count as soon as you
read a character. But the character might appear again later in the
string. So you need to keep track of the characters you have already
read.
Algorithm 2:
String countChar(String s){
has_processed = []
for i = 0 to n
cnt = 0
if s.charAt(i) has been processed
continue;
for j = i+1 to n
if (s.charAt(i) == s.charAt(j))
cnt++
add s.charAt(i) to has_processed array
print the count of s.charAt(i)
}
Use a frequency array to get an answer in linear time.
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
String s = "better butter";
int freq[] = new int[26];
int i;
for (i = 0; i < s.length(); i++) {
if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z')
freq[s.charAt(i)-'a']++;
}
for (i = 0; i < freq.length; i++) {
if (freq[i] == 0) continue;
System.out.println((char)(i+'a') + " appears " + freq[i] + " times" );
}
}
}
Ideone Link
Note that this can be expanded to include uppercase letters, but for demonstrative purposes, only lowercase letters are handled in the above code.
EDIT: While the OP did ask if it was possible to do this without an array, I would recommend against such. That solution would have terrible time complexity and repeat character counts (unless an array is used to keep track of seen characters, which is counter to the aim). Thus, the above solution is the best way to do it in a reasonable amount of time (linear) with limited space consumption.
I would do the following. Create a HashMap which keeps track of which unique characters are in the string and the count for each character.
You only need to iterate over the string once, and put each character into the HashMap. if the characer is in the map, icrement the integer count in the map, else add 1 to the map for that character. Print out the map with toString() to get the result. The whole thing can be done in about 4 lines of code.
The only thing being done in your nested for loop with the following
c = s.charAt(cnt)
is setting the c char to the value of the first letter (i.e. index 0 of the string) over and over and over until you've looped through the string n^2 times. In other words, you're not incrementing your cnt counter within the for loops at all.
Suggestion: try to use meaningful names for your variables; it will help you a lot in your career. Also class names should always start with a capital letter.
Although it is not the quickest solution in terms of performance, the most simple solution should be:
import java.util.HashMap;
import java.util.Map;
...
Map<String, Integer> freq = new HashMap<String, Integer>();
...
int count = freq.containsKey(word) ? freq.get(word) : 0;
freq.put(word, count + 1);
Source: Most efficient way to increment a Map value in Java
Please next time use the search function before posting a new question.
Here is my version of countChar(String s)
boolean countChar(String s) {
if(s==null) return false;
s = s.toUpperCase();
//view[x] will means that the characted in position x has been just read
boolean[] view = new boolean[s.length()];
/*
The main idea is:
foreach character c = s.charAt(x) in the string s, I have a boolean value view[x] which say if I have already examinated c.
If c has not been examinated yet, I search for other characters equals to c in the rest of the string.
When I found other characters equals to c, I mark it as view and I increment count with count++.
*/
for (int i = 0; i < s.length(); i++) {
if (!view[i]) {
char tmp = s.charAt(i);
int count = 0;
for (int j = i; j < s.length(); j++) {
if (!view[j] && s.charAt(j) == tmp) {
count++;
view[j] = true;
}
}
System.out.println("There were " + count + " " + tmp);
}
}
return true;
}
It should work, excuse me for my English because I'm italian

Splitting a string into multiple int form using indexOf()

This is my first post so go easy on me. This IS a homework question, but I have spent about 7 hours working through various means to complete this goal and have had no success. I am building various methods for an assignment, and I need to figure out how to split a String into several int variables.
Ex: given the String "100 200 300" I need to change it to three int of 100, 200, 300. I have to use indexOf(), and cannot use split() or arrays.
String scores="100 200 300";
int n=scores.indexOf(" ");
String sub=scores.substring(0,n);
Integer.parseInt(sub);
This lets me get the first string "100" and parse it. However, I do not know how to continue the code so it will get the next ones. For my method, I will need the new int variables for later arguments.
EDIT: I think I need to use a for loop: something like:
for(int i=0; i<=scores.length; i++)
{//I do not know what to put here}
Joe, indexOf() is overloaded, check out this version:
http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#indexOf(int,%20int)
You need two things:
a loop;
being able to run indexOf() from where it left off (hint: read the Javadoc).
public static void main(String[] args) {
String scores = "100 200 300";
ArrayList<Integer> numbers = new ArrayList<Integer>();
int n = 0;
while (n != -1) {
String sub = "";
n = scores.indexOf(" ");
if (n != -1) {
sub = scores.substring(0, n);
scores = scores.substring((n + 1));
} else {
sub = scores;
}
numbers.add(Integer.parseInt(sub));
}
for (int i : numbers) {
System.out.println("" + i);
}
}
Try something like this to loop through and add numbers to arraylist. The arraylist numbers will contain all your numbers.
try this:
String scores="100 200 300";
int offset = 0;
int space;
int score;
scores = scores.trim(); //clean the string
do
{
space= scores.indexOf(" ", offset);
if(space > -1)
{
score = Integer.parseInt(scores.substring(offset , space));
}
else
{
score = Integer.parseInt(scores.substring(offset));
}
System.out.println(score);
offset = space + 1;
}while(space > -1);
Your 'n' variable is the important part. You get your first String by slicing from 0 to 'n', so your next string starts not at 0, but at
n + " ".size()
Ok, so here is what I have come up with:
Since I needed to compare the newly parsed ints with a different variable, as well as ensure that the amount of ints was equal to a different variable, I created this while loop:
public boolean isValid()
{
int index=0;
int initialindex=0;
int ntotal=0;
int ncount=0;
boolean flag=false;
while (index!=-1)
{
index=scores.indexOf(" ");
String temp=scores.substring(initialindex,index);
int num=Integer.parseInt(temp);
ntotal+=num;
ncount++;
initialindex=index;
}
if (ntotal==total && ncount==count)
{
flag=true;
}
return flag;
}

Categories