Questions

From Progteam

Revision as of 08:04, 18 October 2008 by MuGMaN (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Checkmark.jpg This problem has been solved by Eric.


Questions
Problem Number 2359
Sorter: meeting
Source: Ural Collegiate Programming Contest 1999
Link: http://acm.pku.edu.cn/JudgeOnline/problem?id=2359



Questions is problem number 2359 on the Peking University ACM site.


Contents

Problem Information

Problem Name: Questions
Problem Number on PKU: 2359
Synopsis: Writing a program that automatically answers the questions based on a certain algorithm.

Solver Information

Solver: Eric Hong
Date: October 18, 2008

Trivia

I got a run-time error at first because Scanner did not recognize a space as an input.

General Strategy

  1. Using Scanner, take the input.
  2. If Scanner returns false for hasNext(), automatically add a space.
  3. Populate a Character array list with each character in a string.
  4. Find a new position for the pointer, wrapping around the array.
  5. Get rid of the characters until only one remains.
  6. Using switch statement, print out the final result.


Solution

import java.util.*;

public class Main {

    public static Scanner in;
    public static ArrayList<Character> list = new ArrayList<Character>();
    public static int pointer = 0;
 
    public static void main(String[] args){
        in=new Scanner(System.in);

        doStuff();
    }

   public static void doStuff(){
      String s = "";
		
      if (in.hasNext() == false) 
         s += " ";
		
      while (in.hasNext()) 
         s += in.nextLine();
        
      int len = s.length();
        
      for (int i = 0; i < len; i++) 
         list.add(s.charAt(i));
        
      solve();   
   }

   public static void solve() {	
      final int N = 1999;	
      int round = 1;
      int jump;
      int len = list.size();
		
      while (len > 1) {
         pointer = (pointer + ((N % len) - 1)) % len;
         list.remove(pointer);
	 len = list.size();
      }
		
      char ch = list.get(0);
   
      switch (ch) {
         case '?': System.out.println("Yes"); break;
	 case ' ': System.out.println("No"); break;
	 default: System.out.println("No comments"); break;
      }
   }
}


Additional Remarks

Memory: 4868K
Time: 2219MS

This solution may not be as efficient as it can be.

Personal tools