Can anyone convert Java to C++

import java.util.Scanner;
import java.util.regex.Pattern;

public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
Pattern p = Pattern.compile("[A-F]?A+F+C+[A-F]?");

while(t-- > 0) System.out.println(p.matcher(in.next()).matches() ? "Infected!" : "Good");
}
}
Try this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <string>
#include <regex>

using namespace std;

int main() 
{
  regex re("[A-F]?A+F+C+[A-F]?");

  int t;
  cin >> t;
  cin.ignore(255, '\n');
  while(t--)
  {
    string line;
    getline(cin, line);

    if (regex_match(line, re))
      cout << "Infected\n";
    else
      cout << "Good" << '\n';
  }
}
Topic archived. No new replies allowed.