//Avoid Using Double parsing
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer("");
StringTokenizer st=new StringTokenizer(br.readLine());
int n=Integer.parseInt(st.nextToken());
int m=Integer.parseInt(st.nextToken());
HashMap<String,Integer> hm=new HashMap<String, Integer>();
for(int i=0;i<n;i++){
st=new StringTokenizer(br.readLine());
hm.put(st.nextToken(), mult(st.nextToken()));
}
for(int i=1;i<m+1;i++){
sb.append("Guess #").append(i).append(" was ");
st=new StringTokenizer(br.readLine());
int countofToken=st.countTokens();
double ans=hm.get(st.nextToken());
while(st.hasMoreTokens()){
String temp=st.nextToken();
if(temp.equals("+")){
ans+=hm.get(st.nextToken());
}
if(temp.equals("<")){
if(ans<10*Integer.parseInt(st.nextToken())){
sb.append("correct.\n");
}else{
sb.append("incorrect.\n");
}
}
else if(temp.equals(">")){
if(ans>10*Integer.parseInt(st.nextToken())){
sb.append("correct.\n");
}else{
sb.append("incorrect.\n");
}
}
else if(temp.equals(">=")){
if(ans>=10*Integer.parseInt(st.nextToken())){
sb.append("correct.\n");
}else{
sb.append("incorrect.\n");
}
}
else if(temp.equals("<=")){
if(ans<=10*Integer.parseInt(st.nextToken())){
sb.append("correct.\n");
}else{
sb.append("incorrect.\n");
}
}
else if(temp.equals("=")){
if(ans==10*Integer.parseInt(st.nextToken())){
sb.append("correct.\n");
}else{
sb.append("incorrect.\n");
}
}
}
}
System.out.print(sb);
}
static int mult(String x){
StringBuilder sb=new StringBuilder();
for(int i=0;i<x.length();i++){
if(x.charAt(i)>='0' &&x.charAt(i)<='9'){
sb.append(x.charAt(i));
}
}
return Integer.parseInt(sb.toString());
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer("");
StringTokenizer st=new StringTokenizer(br.readLine());
int n=Integer.parseInt(st.nextToken());
int m=Integer.parseInt(st.nextToken());
HashMap<String,Integer> hm=new HashMap<String, Integer>();
for(int i=0;i<n;i++){
st=new StringTokenizer(br.readLine());
hm.put(st.nextToken(), mult(st.nextToken()));
}
for(int i=1;i<m+1;i++){
sb.append("Guess #").append(i).append(" was ");
st=new StringTokenizer(br.readLine());
int countofToken=st.countTokens();
double ans=hm.get(st.nextToken());
while(st.hasMoreTokens()){
String temp=st.nextToken();
if(temp.equals("+")){
ans+=hm.get(st.nextToken());
}
if(temp.equals("<")){
if(ans<10*Integer.parseInt(st.nextToken())){
sb.append("correct.\n");
}else{
sb.append("incorrect.\n");
}
}
else if(temp.equals(">")){
if(ans>10*Integer.parseInt(st.nextToken())){
sb.append("correct.\n");
}else{
sb.append("incorrect.\n");
}
}
else if(temp.equals(">=")){
if(ans>=10*Integer.parseInt(st.nextToken())){
sb.append("correct.\n");
}else{
sb.append("incorrect.\n");
}
}
else if(temp.equals("<=")){
if(ans<=10*Integer.parseInt(st.nextToken())){
sb.append("correct.\n");
}else{
sb.append("incorrect.\n");
}
}
else if(temp.equals("=")){
if(ans==10*Integer.parseInt(st.nextToken())){
sb.append("correct.\n");
}else{
sb.append("incorrect.\n");
}
}
}
}
System.out.print(sb);
}
static int mult(String x){
StringBuilder sb=new StringBuilder();
for(int i=0;i<x.length();i++){
if(x.charAt(i)>='0' &&x.charAt(i)<='9'){
sb.append(x.charAt(i));
}
}
return Integer.parseInt(sb.toString());
}
}
No comments:
Post a Comment