You are not logged in. Please login at www.codechef.com to post your questions!

×

# What is the problem with my code?

 0 using System; using System.Text; namespace Orders { class Program { static int Main(string[] args) { int numberOfTestCases = Convert.ToInt16(Console.ReadLine()); for (int i = 0; i < numberOfTestCases; i++) { int size = Convert.ToInt16(Console.ReadLine()); int[] arr = new int[size]; for (int k = 0; k < size; k++) { StringBuilder sb = new StringBuilder(); char c; while (true) { c = Convert.ToChar(Console.Read()); if (c == ' ' || c == '\n') break; sb.Append(c); } arr[k] = Convert.ToInt16(sb.ToString()); } //Input completed MyLinkedList stack = new MyLinkedList(arr); stack.reArrange(); stack.populateRank(); stack.printRank(); } return 0; } } class MyLinkedList { public MyLinkedList(int[] arr) { Head = null; Tail = null; Count = 0; rank = new int[arr.Length]; for (int i = 0; i < arr.Length; i++) { this.addNode(arr[i], i); } } public int[] rank; public class Node { public int val; public int mov; public Node left; public Node right; } public Node Head { get; set; } public Node Tail { get; set; } public int Count { get; set; } public void addNode(int n, int k) { Node node = new Node { val = k, mov = n }; if (this.Count == 0) { this.Head = node; this.Tail = node; this.Count++; } else { node.left = this.Tail; node.right = this.Head; this.Head.left = node; this.Tail.right = node; this.Tail = node; this.Count++; } } public void populateRank() { Node temp = this.Head; for (int i = 0; i < this.Count; i++) { rank[temp.val] = i + 1; temp = temp.right; } } public void printRank() { string str = ""; for (int i = 0; i < rank.Length - 1; i++) { str += rank[i].ToString() + " "; } str += rank[rank.Length-1].ToString(); Console.WriteLine(str); } public void reArrange() { Node cur = this.Head; int i = 0; while (i

 0 I'm getting runtime error (OTHERS) answered 30 Mar '12, 11:51 1●2●2●2 accept rate: 0% please provide us a link toward the problem statement. (30 Mar '12, 18:02) http://www.codechef.com/problems/ORDERS (30 Mar '12, 23:26)
 0 if (c == ' ' || c == '\n')  maybe you should rather check if c is not a digit. you can't be really sure of what the input string is made (there could be '\t' or '\r' in the line, even alpha chars...). it's a hard-to-detect problem, as when we generate sample test cases ourselves, the code is obviously written in order to parse the data correctly. but when submitted to the online judge, who knows what can happen. :) please tell us if you get AC with that. otherwise, i'll try to go deeper into your code. good luck. answered 31 Mar '12, 00:20 3.4k●2●19●55 accept rate: 20%
 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×461
×58

question asked: 30 Mar '12, 11:50

question was seen: 1,101 times

last updated: 25 Jun '12, 12:45