本文整理汇总了C#中System.IO.TextReader.ReadLine方法的典型用法代码示例。如果您正苦于以下问题:C# TextReader.ReadLine方法的具体用法?C# TextReader.ReadLine怎么用?C# TextReader.ReadLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.TextReader
的用法示例。
在下文中一共展示了TextReader.ReadLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Solve
//public static void Main(string[] args) {
// new ProblemC().Solve(Console.In);
//}
private void Solve(TextReader input)
{
var nx = input.ReadLine().Split(' ').Select(int.Parse).ToList();
var n = nx[0];
var x = nx[1];
var values = input.ReadLine().Split(' ').Select(int.Parse)
.OrderBy(i => i)
.ToList();
var counts = new int[3];
foreach (var value in values) {
counts[value.CompareTo(x) + 1]++;
}
var mid = (values.Count - 1) / 2;
if (values[mid] == x) {
Console.WriteLine(0);
} else if (values[mid] < x) {
// 000xx2
Console.WriteLine(counts[0] - (counts[2] + counts[1]) + 1);
} else {
// 0xx2222
Console.WriteLine(counts[2] - (counts[0] + counts[1]));
}
}
示例2: Answer
public static void Answer(TextReader reader)
{
int n = Convert.ToInt32(reader.ReadLine());
int[] coordinates = reader.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
List<Line> lines = new List<Line>();
for (int index = 0; index < coordinates.Length - 1; index++)
{
int a = coordinates[index];
int b = coordinates[index + 1];
lines.Add(new Line {From = Math.Min(a,b), To = Math.Max(a,b)});
}
for (int i = 0; i < lines.Count; i++)
{
for(int j = 0; j< lines.Count; j++)
{
if (intersect(lines[i], lines[j]))
{
Console.WriteLine("yes");
return;
}
}
}
Console.WriteLine("no");
}
示例3: GetKnapsack
public static Knapsack GetKnapsack(TextReader reader)
{
Contract.Requires<ArgumentNullException>(reader != null, "reader");
var firstRow = reader.ReadLine();
var firtsRowParts = firstRow.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
int capacity = int.Parse(firtsRowParts[0]);
int numberOfItems = int.Parse(firtsRowParts[1]);
var items = new List<KnapsackItem>(numberOfItems);
while (true)
{
string row = reader.ReadLine();
if (row == null)
{
break;
}
var parts = row.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
var parameters = parts.Select(x => int.Parse(x, CultureInfo.InvariantCulture)).ToArray();
items.Add(new KnapsackItem(parameters[0], parameters[1]));
}
return new Knapsack(items, capacity);
}
示例4: Load
public void Load(TextReader reader)
{
var verse = new List<string> ();
for (var line = reader.ReadLine (); line != null; line = reader.ReadLine ()) {
var tline = line.Trim ();
if (tline.Length == 0 || tline [0] == '#') {
continue;
}
if (line [0] == '.' || line [0] == '/' || line [0] == '!') {
if (verse.Count > 0) {
LoadVerse (verse);
}
verse = new List<string> ();
}
verse.Add (line);
}
if (verse.Count > 0) {
LoadVerse (verse);
}
}
示例5: Read
public static TestCaseConfig Read(TextReader reader)
{
var line = reader.ReadLine().Trim();
Assert.AreEqual("/*---", line);
var lines = new List<string>();
string rawLine;
while((line = (rawLine = reader.ReadLine()).Trim()) != "---" && line != "*/")
lines.Add(rawLine);
var vson = string.Join("\r\n", lines);
var config = JsonConvert.DeserializeObject<TestCaseConfig>(vson);
if(line == "---")
{
// read in expected console output
lines.Clear();
while((line = (rawLine = reader.ReadLine()).Trim()) != "*/")
lines.Add(rawLine);
config.VerifyConsoleOutput = true;
config.ExpectedConsoleOutput = string.Join("\r\n", lines);
}
return config;
}
示例6: Read
/// <summary>Read in rating data from a TextReader</summary>
/// <param name="reader">the <see cref="TextReader"/> to read from</param>
/// <param name="user_mapping">mapping object for user IDs</param>
/// <param name="item_mapping">mapping object for item IDs</param>
/// <param name="ignore_first_line">if true, ignore the first line</param>
/// <returns>the rating data</returns>
public static IRatings Read(TextReader reader, IMapping user_mapping = null, IMapping item_mapping = null, bool ignore_first_line = false)
{
if (user_mapping == null)
user_mapping = new IdentityMapping();
if (item_mapping == null)
item_mapping = new IdentityMapping();
if (ignore_first_line)
reader.ReadLine();
var ratings = new Ratings();
string line;
while ( (line = reader.ReadLine()) != null )
{
if (line.Length == 0)
continue;
string[] tokens = line.Split(Constants.SPLIT_CHARS);
if (tokens.Length < 3)
throw new FormatException("Expected at least 3 columns: " + line);
int user_id = user_mapping.ToInternalID(tokens[0]);
int item_id = item_mapping.ToInternalID(tokens[1]);
float rating = float.Parse(tokens[2], CultureInfo.InvariantCulture);
ratings.Add(user_id, item_id, rating);
}
ratings.InitScale();
return ratings;
}
示例7: Read
Read(TextReader reader)
{
var candidates = new Dictionary<int, IList<int>>();
string line;
while ( (line = reader.ReadLine()) != null )
{
string[] tokens = line.Split('|');
int user_id = int.Parse(tokens[0]);
int num_ratings = int.Parse(tokens[1]); // number of ratings for this user
var user_candidates = new int[num_ratings];
for (int i = 0; i < num_ratings; i++)
{
line = reader.ReadLine();
user_candidates[i] = int.Parse(line);
}
candidates.Add(user_id, user_candidates);
}
return candidates;
}
示例8: Solve
//private static void Main(string[] args) {
// new ProblemB().Solve(Console.In);
//}
private void Solve(TextReader input)
{
var ns = input.ReadLine().Split(' ').ToArray();
var ns2 = new[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" };
var ns3 = new[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
var count = int.Parse(input.ReadLine());
var vs = new List<string>();
for (int i = 0; i < count; i++) {
vs.Add(input.ReadLine().Trim());
}
var answer = vs.Select(
v => {
var result = v;
foreach (var t in ns.Zip(ns2, Tuple.Create)) {
result = result.Replace(t.Item1, t.Item2);
}
foreach (var t in ns2.Zip(ns3, Tuple.Create)) {
result = result.Replace(t.Item1, t.Item2);
}
return Tuple.Create(v, result);
}).Select(t => Tuple.Create(t.Item1, int.Parse(t.Item2))).OrderBy(t => t.Item2);
foreach (var t in answer) {
Console.WriteLine(t.Item1);
}
}
示例9: LoadDataFile
public void LoadDataFile()
{
fileReader = new StreamReader(filename);
if (System.IO.File.Exists(filename) == false)
{
throw new System.InvalidOperationException("Error: " + filename + " could not be found.");
}
saveData.Clear();
string line = "";
string read = "";
line = fileReader.ReadLine();
while (line != null)
{
for (int i = 0; i < line.Length; i++)
{
if (line[i] != '=')
{
read += line[i];
}
else
{
string status = line.Substring(i+1, (line.Length - (i+1) ));
saveData.Add(read, Convert.ToBoolean(status));
}
}
read = "";
line = fileReader.ReadLine();
}
fileReader.Close();
}
示例10: ParseHooks
public static List<Hook> ParseHooks(TextReader reader)
{
var hooks = new List<Hook>();
var currentLine = reader.ReadLine();
while (currentLine != null)
{
if (currentLine[0] == '"')
{
var cmdEndIndex = currentLine.IndexOf('"', 1);
if (cmdEndIndex < 0)
throw new HooksParserException("Unterminated quotes.");
if (currentLine.Length > cmdEndIndex + 1 && currentLine[cmdEndIndex + 1] != ' ')
throw new HooksParserException("Command and argument not separated by a space.");
if (currentLine.Length <= cmdEndIndex + 2)
hooks.Add(new Hook() { Command = currentLine.Substring(1, cmdEndIndex - 1) });
else
hooks.Add(new Hook() { Command = currentLine.Substring(1, cmdEndIndex - 1), Arguments = currentLine.Substring(cmdEndIndex + 2, currentLine.Length - (cmdEndIndex + 2)) });
}
else
{
var spaceIndex = currentLine.IndexOf(' ');
if (spaceIndex < 0 || spaceIndex >= currentLine.Length - 1)
hooks.Add(new Hook() { Command = currentLine });
else
hooks.Add(new Hook() { Command = currentLine.Substring(0, spaceIndex), Arguments = currentLine.Substring(spaceIndex + 1, currentLine.Length - (spaceIndex + 1)) });
}
currentLine = reader.ReadLine();
}
return hooks;
}
示例11: Answer
public void Answer(TextReader input)
{
string line = input.ReadLine();
int nOfCases = Convert.ToInt32(line);
bool[] DP = new bool[100000000000000];
for (int caseNo = 1; caseNo <= nOfCases; caseNo++)
{
//Size
line = input.ReadLine();
long low = Convert.ToInt64(line.Split(' ')[0]);
long hi = Convert.ToInt64(line.Split(' ')[1]);
long result = 0;
for (long i = 1; i * i <= hi; i++)
{
if(i * i >= low)
{
if (IsPalindrome(i) && IsPalindrome(i * i))
{
DP[i] = true;
result++;
}
}
}
Console.Out.WriteLine("Case #{0}: {1}", caseNo, result);
}
}
示例12: Solve
private void Solve(TextReader reader)
{
var nTestCases = int.Parse(reader.ReadLine().Trim());
for (int iTestCases = 0; iTestCases < nTestCases; iTestCases++) {
var nVines = int.Parse(reader.ReadLine().Trim());
var vines = Enumerable.Repeat(0, nVines)
.Select(
_ => {
var values = reader.ReadLine().Split(' ').Select(int.Parse).ToList();
return new Vine(values[0], values[1], 0);
})
.ToList();
var distance = int.Parse(reader.ReadLine().Trim());
vines[0].Height = Math.Min(vines[0].Length, vines[0].Pos);
var maxDistance = 0;
for (int iVines = 0; iVines < nVines; iVines++) {
if (vines[iVines].Height <= 0) {
continue;
}
var d = vines[iVines].Pos + vines[iVines].Height;
maxDistance = Math.Max(maxDistance, d);
for (int i = iVines + 1; i < nVines && vines[i].Pos <= d; i++) {
vines[i].Height = Math.Max(
vines[i].Height,
Math.Min(vines[i].Length, vines[i].Pos - vines[iVines].Pos));
}
}
var answer = maxDistance >= distance;
Console.WriteLine(
"Case #" + (iTestCases + 1) + ": " + (answer ? "YES" : "NO"));
}
}
示例13: Read
private void Read(TextReader reader)
{
var line = reader.ReadLine();
ulong commitNumber, tripleCount;
if (!UInt64.TryParse(line, out commitNumber))
{
throw new BrightstarInternalException(
"Error reading statistics record. Could not parse commit number line.");
}
CommitNumber = commitNumber;
line = reader.ReadLine();
if (!UInt64.TryParse(line, out tripleCount))
{
throw new BrightstarInternalException(
"Error reading statistics record. Could not parse triple count line.");
}
TotalTripleCount = tripleCount;
while (true)
{
line = reader.ReadLine();
if (String.IsNullOrEmpty(line) || line.Equals("END")) break;
var splitIx = line.IndexOf(',');
if (UInt64.TryParse(line.Substring(0, splitIx), out tripleCount))
{
string predicate = line.Substring(splitIx + 1);
PredicateTripleCounts[predicate] = tripleCount;
}
}
}
示例14: ReadFacet
/// <summary>
/// Read a facet
/// </summary>
protected virtual Facet ReadFacet(TextReader reader)
{
Facet facet = new Facet();
// Read the normal
if ((facet.Normal = ReadVertex(reader, facetRegex)) == null)
return null;
// Skip the "outer loop"
reader.ReadLine();
// Read the vertices
for (int i = 0; i < 3; i++)
{
var vertice = ReadVertex(reader, verticeRegex);
if (vertice == null) return null;
facet.Vertices.Add(vertice);
}
// Read the "endloop" and "endfacet"
reader.ReadLine();
reader.ReadLine();
return facet;
}
示例15: Parse
/// <summary>
/// Parses the specified reader.
/// </summary>
/// <param name="reader">The reader.</param>
/// <param name="from">From.</param>
/// <param name="to">To.</param>
/// <returns></returns>
/// <remarks></remarks>
public Modification[] Parse(TextReader reader, DateTime from, DateTime to)
{
var mods = new List<Modification>();
string currentLine = reader.ReadLine();
while (currentLine != null)
{
// TODO - do it all with a regex?
if (currentLine.Contains(DELETED_DIR_TAG))
{
mods.Add(ParseDeletedDirectory(currentLine));
}
else if (currentLine.Contains(DELETED_FILE_TAG))
{
mods.Add(ParseDeletedFile(currentLine));
}
else if (currentLine.Contains(ADDED_FILE_TAG))
{
mods.Add(ParseAddedFile(currentLine));
}
else if (currentLine.Contains(UPDATED_FILE_TAG))
{
mods.Add(ParseUpdatedFile(currentLine));
}
currentLine = reader.ReadLine();
}
return mods.ToArray();
}