本文整理汇总了C#中Scanner.nextInt方法的典型用法代码示例。如果您正苦于以下问题:C# Scanner.nextInt方法的具体用法?C# Scanner.nextInt怎么用?C# Scanner.nextInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scanner
的用法示例。
在下文中一共展示了Scanner.nextInt方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: calc
void calc()
{
Scanner cin = new Scanner();
int n = cin.nextInt();
int[] r = new int[n];
int i, j;
Dictionary<int, int> dic = new Dictionary<int, int>();
for (i = 0; i < n; i++)
{
r[i] = cin.nextInt();
if (!dic.ContainsKey(r[i])) dic[r[i]] = 0;
dic[r[i]]++;
}
if (dic.Count < 3)
{
Console.WriteLine(0);
return;
}
long MAX = (long)1e10;
Heap h = new Heap(0);
foreach (var item in dic)
{
h = meld(h, new Heap(MAX * item.Value + item.Key));
}
int[,] ret = new int[n, 3];
int retnum = 0;
for (j = 0; ; j++)
{
long[] num = new long[3];
for (i = 0; i < 3; i++)
{
num[i] = h.val;
h = meld(h.r, h.l);
}
if (num[2] < MAX) break;
int[] nums = new int[3];
for (i = 0; i < 3; i++)
{
nums[i] = (int)(num[i] % MAX);
num[i] -= MAX;
}
for (i = 0; i < 3; i++)
{
h = meld(h, new Heap(num[i]));
}
Array.Sort(nums);
Array.Reverse(nums);
for (i = 0; i < 3; i++)
{
ret[j, i] = nums[i];
}
retnum++;
}
Console.WriteLine(retnum);
for (i = 0; i < retnum; i++)
{
Console.WriteLine("{0} {1} {2}", ret[i, 0], ret[i, 1], ret[i, 2]);
}
}
示例2: getAutoTests
private void getAutoTests(string baseDir, XElement testFileRunner, List<MainTestData> explicitCases)
{
Logger.LogInfo("get auto tests {} {}", baseDir,
explicitCases.Select(td => td.mainClassName).ToCommaString());
string nsPrefix = getAttributeValue(testFileRunner, "namespacePrefix");
string assemblyName = getAttributeValue(testFileRunner, "assemblyName");
Assembly assembly = Assembly.Load(assemblyName);
Preconditions.checkState(assembly != null, "Assembly null");
Preconditions.checkState(assembly.GetTypes() != null);
//Logger.LogInfo("nsPrefix {} assemblyName {}", nsPrefix, assemblyName);
//Logger.LogInfo("Types {}", assembly.GetTypes().Count());
Type[] types = assembly.GetTypes().Where
(t => (t.Namespace ?? "").StartsWith(nsPrefix)).OrderBy(t => t.Namespace).ToArray();
foreach(Type type in types)
{
MethodInfo m = type.GetMethod("createInput");
if (m == null)
continue;
string mainClassName = type.AssemblyQualifiedName;
Logger.LogTrace("Type {} method {} mainClass {}", type, m, mainClassName);
Regex regex = new Regex(@".*Problem(\d).*");
string letter = "" + (char) ('A' + int.Parse(regex.Match(type.Namespace).Groups[1].Value) - 1);
foreach(string inputFileName in
new DirectoryInfo(baseDir).GetFiles(letter + "*.in").Select(fi => fi.Name))
{
//string inputFileName = letter + "-small-practice.in";
string checkFileName = new Regex(@"\.in$").Replace(inputFileName, ".correct");
string inputMethodName = "createInput";
string processInputMethodName = "processInput";
if (explicitCases.Any( td =>
td.mainClassName.StartsWith(type.FullName)
&& td.inputFileName.Equals(inputFileName)
&& td.processInputMethodName.Equals(processInputMethodName)
))
{
Logger.LogInfo("Skipping {} {} {} {}",
type.FullName,
processInputMethodName,
inputFileName,
inputMethodName);
continue;
}
TextReader inputReader = File.OpenText(inputFileName);
Scanner scanner = new Scanner(inputReader);
using (TextReader checkReader = File.OpenText(checkFileName))
{
int testCases = scanner.nextInt();
//Logger.LogInfo("Begin testing class {} method {} testcases {}",
// mainClassName, processInputMethodName, testCases);
List<string> checkStrs = new List<string>();
PeekingStreamReader peekSR = new PeekingStreamReader(checkReader);
for (int tc = 1; tc <= testCases; ++tc)
{
StringBuilder sb = new StringBuilder();
string line;
//while (true //
//&& (string line = peekSR.ReadLine()) != null )
while( (line = peekSR.ReadLine()) != null)
{
sb.Append(line);
sb.Append("\n");
if (new Regex(@"Case #" + (tc+1)).Match(peekSR.PeekReadLine() ?? "").Success)
{
break;
}
}
sb.Length --;
//sb.RemoveAt(sb.Count() - 1);
checkStrs.Add(sb.ToString());
}
testList.Add(new MainTestData
{
//.........这里部分代码省略.........
示例3: ReadTestFileCases
public void ReadTestFileCases()
{
Logger.LogInfo("ReadTestFileCases");
testList = new List<MainTestData>();
XElement po = XElement.Load(setBaseDir(@"TestData.xml", false));
foreach (XElement testFileRunner in po.Elements("testFileRunner"))
{
string baseDir = getAttributeValue(testFileRunner, "basedir");
string autotest = getAttributeValue(testFileRunner, "autotest");
baseDir = setBaseDir(baseDir);
Logger.LogDebug("base dir {}", baseDir);
List<MainTestData> explicitCases = new List<MainTestData>();
foreach (XElement run in testFileRunner.Elements("run"))
{
string mainClassName = getAttributeValue(run, "className");
string inputFileName = getAttributeValue(run, "inputFile");
string checkFileName = getAttributeValue(run, "checkFile");
string inputMethodName = getAttributeValue(run, "createInputMethod");
string processInputMethodName = getAttributeValue(run, "processInputMethod");
TextReader inputReader = File.OpenText(inputFileName);
Scanner scanner = new Scanner(inputReader);
using (TextReader checkReader = File.OpenText(checkFileName))
{
int testCases = scanner.nextInt();
//Logger.LogInfo("Begin testing class {} method {} testcases {}",
// mainClassName, processInputMethodName, testCases);
List<string> checkStrs = new List<string>();
for (int tc = 1; tc <= testCases; ++tc)
{
checkStrs.Add(checkReader.ReadLine());
}
testList.Add(new MainTestData
{
baseDir = baseDir,
mainClassName = mainClassName,
inputMethodName = inputMethodName,
inputFileName = inputFileName,
processInputMethodName = processInputMethodName,
scanner = scanner,
checkStrList = checkStrs,
testCases = testCases,
category = getAttributeValue(run, "category"),
testName = getAttributeValue(run, "testName"),
testDescription = string.Format("Class {0}\nMethod {1} \ninput file {2}",
mainClassName, processInputMethodName, inputFileName)
});
explicitCases.Add(testList[testList.Count-1]);
}
}
if ("true".Equals(autotest)) {
getAutoTests(baseDir, testFileRunner, explicitCases);
}
}
}
示例4: loadGame
/// <summary>
/// Loads a saved game
/// </summary>
public void loadGame(string fileName = @"playersave.dat")
{
Scanner k;
try {
k = new Scanner(System.IO.File.ReadAllText(Application.persistentDataPath + @"\" + @fileName));
}
catch (FileNotFoundException e)
{
print("File not found");
return;
}
string word;
do
{
word = k.getNextWord();
switch (word)
{
case "NAME":
this.name = k.getNextWord();
break;
case "MONEY":
Inventory.inv.setMoney(k.nextInt());
break;
case "PAY":
Inventory.inv.setPay(k.nextInt());
break;
case "BOSSLEVEL":
LevelState.cur.setBossLevel(k.nextInt());
break;
case "INVENTORY":
loadInventory(k);
break;
case "WORKERS":
loadWorkers(k);
break;
default:
print("Error Parsing Save File: Unexpected Keyword '" + @word + "'");
return;
}
} while (k.hasNext());
}
示例5: Main
static void Main(String[] args)
{
Options options = new Options();
if (!options.parse(args)) {
//return;
}
Scanner scanner = new Scanner();
// Take all the parameters from the input
double a, b;
int N;
int fx;
int _realN;
// ------ lower limit input -----
Console.Write("Ingrese a: ");
if (options.isASet) {
a = options.a;
Console.WriteLine(a);
} else {
a = scanner.nextDouble();
}
// ------ upper limit input -----
Console.Write("Ingrese b: ");
if (options.isBSet) {
b = options.b;
Console.WriteLine(b);
} else {
b = scanner.nextDouble();
}
// ------ number of partitions input -----
Console.Write("Ingrese N: ");
if (options.isNumPartitionsSet) {
N = options.numPartitions;
Console.WriteLine(N);
} else {
N = scanner.nextInt();
}
_realN = 3 * N;
Console.WriteLine("Seleccione la funcion a integrar (1 - {0}):", functions.Length);
for (int i = 0; i < functions.Length; i++) {
Console.WriteLine(" opcion #{0}: {1}", i, functions[i].GetName());
}
// ------ function index input ------
if (options.isFxSet) {
Console.Write(" ingrese la opcion: ");
fx = options.fx;
Console.WriteLine(fx);
} else {
do {
Console.Write(" ingrese la opcion: ");
fx = scanner.nextInt();
} while (fx < 0 || fx >= functions.Length);
}
Console.WriteLine();
// ----- begin to calculate the final results -----
double h = (b - a) / _realN;
Console.WriteLine("Resultado Integracion:");
Console.WriteLine("==========================");
Console.WriteLine();
Console.WriteLine("Funcion a integrar : {0}", functions[fx].GetName());
Console.WriteLine("Numero de particiones : 3 * (N={0}) = {1}", N, _realN);
Console.WriteLine("Limite inferior : {0}", a);
Console.WriteLine("Limite superior : {0}", b);
Console.WriteLine("Paso (h = (b-a)/N) : {0}", h);
// ----- solve and print the final result -----------
MainSolver solver = new MainSolver(a, b, h, _realN, functions[fx]);
double result = solver.ExecuteThreads();
Console.WriteLine("Resultado de integracion: {0}", result);
}