C#,269267字节
打高尔夫球
(l,t)=>{var h=System.DateTime.MinValue;var s=System.DateTime.ParseExact(t,"HH:mm",null);var o="";foreach(var p in l.Split('\n')){var i=p.Split(' ');h=h.Ticks<1?System.DateTime.ParseExact(i[1],"HH:mm",null):h.AddMinutes(int.Parse(i[1]));if(h>s)o+=i[0]+" ";}return o;};
不打高尔夫球
( l, t ) => {
var h = System.DateTime.MinValue;
var s = System.DateTime.ParseExact( t, "HH:mm", null );
var o = "";
foreach( var p in l.Split( '\n' ) ) {
var i = p.Split( ' ' );
h = h.Ticks < 1
? System.DateTime.ParseExact( i[ 1 ], "HH:mm", null )
: h.AddMinutes( int.Parse( i[ 1 ] ) );
if( h > s )
o += i[ 0 ] + " ";
}
return o;
};
非高尔夫可读
( l, t ) => {
// var to check the time of arrival
var h = System.DateTime.MinValue;
// var to store the start time of the party
var s = System.DateTime.ParseExact( t, "HH:mm", null );
// var with the names of those who arrived late
var o = "";
// Cycle through which line
foreach( var p in l.Split( '\n' ) ) {
// Split the name and time
var i = p.Split( ' ' );
// Check if the time of arrival still has the initial value
h = h.Ticks < 1
// If so, grab the time of the first person
// Expects to have a time format of 'hh:mm'
? System.DateTime.ParseExact( i[ 1 ], "HH:mm", null )
// Otherwise, add the difference to the var
: h.AddMinutes( int.Parse( i[ 1 ] ) );
// Check if the current time is later than the party start time
if( h > s )
// If so, add the name to the list
o += i[ 0 ] + " ";
}
// Return the names of the persons who arrived late
return o;
};
完整代码
using System;
using System.Collections.Generic;
namespace Namespace {
class Program {
static void Main( String[] args ) {
Func<String, String, String> f = ( l, t ) => {
var h = System.DateTime.MinValue;
var s = System.DateTime.ParseExact( t, "HH:mm", null );
var o = "";
foreach( var p in l.Split( '\n' ) ) {
var i = p.Split( ' ' );
h = h.Ticks < 1
? System.DateTime.ParseExact( i[ 1 ], "HH:mm", null )
: h.AddMinutes( int.Parse( i[ 1 ] ) );
if( h > s )
o += i[ 0 ] + " ";
}
return o;
};
List<KeyValuePair<String, String>>
testCases = new List<KeyValuePair<String, String>> {
new KeyValuePair<String, String>(
"Kevin 13:02\nRuby 5\nSam 3\nLisa 6\nBob 12",
"13:15"
),
new KeyValuePair<String, String>(
"Kevin 13:15\nRuby 5\nSam 3\nLisa 6\nBob 12",
"13:15"
),
};
foreach( KeyValuePair<String, String> testCase in testCases ) {
Console.WriteLine( $" Input:\n{testCase.Key}\n\n{testCase.Value}\n\nOutput:\n{f( testCase.Key, testCase.Value )}\n" );
}
Console.ReadLine();
}
}
}
发布
笔记