Skip to content

Instantly share code, notes, and snippets.

@nastajus
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nastajus/21452b85fbfebc1df64e to your computer and use it in GitHub Desktop.
Save nastajus/21452b85fbfebc1df64e to your computer and use it in GitHub Desktop.
SPOJ _4138_DOUGHNUT wrong answer for problem here: http://www.spoj.com/problems/DOUGHNUT/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _4138_DOUGHNUT
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter t");
//get input
int t = int.Parse(Console.ReadLine());
List<Datum> list = new List<Datum>();
for (int i = 0; i < t; i++){
string[] split = Console.ReadLine().Split(' ');
list.Add(new Datum(split));
}
//provide output
for (int i = 0; i < list.Count(); i++)
{
Console.Write(list[i].check());
}
//just keeps window open, disabled for online submission
//Console.ReadLine();
}
}
class Datum
{
private int k;
private int w;
private int c;
public Datum(string[] split)
{
c = int.Parse(split[0]);
k = int.Parse(split[1]);
w = int.Parse(split[2]);
}
public string check()
{
if (c * w > k) { return "no\n"; }
else return "yes\n";
}
}
}
/*
* Learning opportuntiies encountered:
* 1- by making my inner class static, i got an error declaring my list of that type. This wasn't the case in Java.
* I should determine why this difference exists, until satisified. The error was: "static arguments cannot be
* used as type arguments"
* 2- why do C# constructors have more granularity of access modifiers (public, private) than Java?
* While trying to construct a new Datum object, got an error. The error was: "Datum does not contain a
* constrcutor that takes 1 argument". Obviously this needs public, and obviously this is more control than Java.
* I suppose a better question would be why doesn't Java do this? ... Oh, because their inner classes are static...
* OK NOW A GOOD QUESTION FOR ME: What does it mean to have a static class? It's basically equivalent to having
* public access. Interesting conclusion
* 3- why does C# have more writable code with indices for lists? i.e. list[i].check() vs. list.get(i).check().
* Or perhaps a more valuable exercise is why does java not have such an amenity, as in, is it difficult to
* implement? OK NOW SOME GOOD QUESTIONS FOR ME: A) Is it possible for me write my own indexer? B) Is this
* equivalent to implementing enumerable? A- A quick google makes me think yes, but haven't really tried. B- based
* on the same google search, it looks like a seperate kind of implementation. C) What is an enumerable?
* C- I'm now led to believe I need a better formed question to ask about enumerables. C.2) How do enumerables work?
* Yes, that's a good question.
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/**
* Created by IAN on 30/08/14.
*/
class Problem {
public static void main(String args[]){
BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );
try {
// get input
int t = Integer.parseInt(br.readLine());
List<Datum> list = new ArrayList<Datum>();
for (int i = 0; i < t; i++){
String[] split = br.readLine().split(" ");
list.add( new Datum(split) );
}
//provide output
for (int i = 0; i < list.size(); i++){
System.out.print( list.get(i).check() );
}
// }
// catch (NumberFormatException nfe){
// System.err.println("Invalid format!");
} catch (IOException e) {
e.printStackTrace();
}
}
static class Datum{ //solved by KEEPING static here. jesus.
public int k; //solved by removing static here. jesus.
public int w; //solved by removing static here. jesus.
public int c; //solved by removing static here. jesus.
Datum(String[] split){
c = Integer.parseInt(split[0]);
k = Integer.parseInt(split[1]);
w = Integer.parseInt(split[2]);
}
public String check(){
if (c*w>k){ return "no\n"; }
else return "yes\n";
// if(c*w <= k) return "yes\n";
// else return "no\n";
}
}
}
/*
* learning opportunities encountered:
* 1- basically more about inheritance of Reader, and basically how to understand the API I'm reading.
* when I pressed F12 on constructors of BufferedReader, etc. I quickly became dizzy and annoyed, giving up.
* Instead what I should do is formulate further postulates how to actually read this, (i.e. what acknowledge what
* OO principles I'm missing in my knowledge, and fix them. I now grant myself permission to ignore that, given
* that my current focus is solving problem #4138_DOUGHNUT, and that I fully accept I must come back to do the work
* of understanding and filling in my gaps with OO that this reminded me of.
* 2- Implications of assigning an ArrayList to a List. That is, fully understanding the benefits of instantiating
* an inherited class assigned to abstract class type. i.e. List<int> list = new ArrayList<int>();
* 3- why the inner class needs to be static - i merely googled it's necessary when i got an error trying to
* instantiate an inner class - the error tool top was: "Problem.this cannot be referenced from a static context".
* 4- why did i have a class starting with public class ABC? Does that access specifier there make sense in that
* location? obviously not since the online compiler rejected it. If IntelliJ added it I blame it, but it's more
* likely it's my fault that I typed it myself. Not important enough to reproduce now.
*
* Main.java:10: class Problem is public, should be declared in a file named Problem.java
* public class Problem {
* ^
* 1 error
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment