-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVirusOutbreak.java
More file actions
60 lines (47 loc) · 1.25 KB
/
VirusOutbreak.java
File metadata and controls
60 lines (47 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/***********************************
* AlgoSolutions Project
* Filename: VirusOutbreak.java
* Author : malay
* Date : 13-Jun-2021
*
**********************************/
package com.contest.techgig.y2021;
import java.util.Scanner;
public class VirusOutbreak {
private static final String NEGATIVE = "NEGATIVE";
private static final String POSITIVE = "POSITIVE";
public static void main(String args[]) throws Exception {
Scanner s = new Scanner(System.in);
String compositionStr = s.nextLine();
int noOfTest = s.nextInt();
s.nextLine();
if (noOfTest < 1 || noOfTest > 10) {
System.out.println("Error");
System.exit(0);
}
int i = 0;
while (i < noOfTest) {
String testStr = s.nextLine();
String result = getResult(compositionStr, testStr);
System.out.println(result);
i++;
}
s.close();
}
private static String getResult(String compositionStr, String testStr) {
char[] compoArr = compositionStr.toCharArray();
char[] testArr = testStr.toCharArray();
int iCompo = 0;
int iTest = 0;
while (iTest < testArr.length) {
while (iCompo < compoArr.length && testArr[iTest] != compoArr[iCompo]) {
iCompo++;
}
if (iCompo >= compoArr.length) {
return NEGATIVE;
}
iTest++;
}
return POSITIVE;
}
}