-
+131
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
private static int GetCarMaxRoomNumberNominal(string trainName, TrainCar car)
{
if (!String.IsNullOrEmpty(trainName))
{
trainName = trainName.ToUpper();
if (trainName.StartsWith("САПСАН"))
{
return 66;
}
else if (trainName.StartsWith("ЛАСТОЧКА"))
{
return 103;
}
else if (trainName.StartsWith("АЛЛЕГРО"))
{
return 72;
}
}
switch (car.Category)
{
case TrainCarCategory.ReservedSeat:
case TrainCarCategory.Common:
return 54;
case TrainCarCategory.Compartment:
return car.TwoStorey ? 112 : 36;
case TrainCarCategory.Lux:
case TrainCarCategory.Soft:
return car.TwoStorey ? 96 : 18;
case TrainCarCategory.Sedentary:
if (car.ServiceClass.Contains("1С"))
{
return 42;
}
else if (car.ServiceClass.Contains("2С"))
{
return 80;
}
if (car.ServiceClass.Contains("3С"))
{
return 117;
}
return 1;
default:
return 1;
}
}
Расчет количества мест в вагоне
Shadeglare,
10 Ноября 2013
-
+108
- 1
assert(buf=malloc(BUF_SIZ));
А в релизе мы сэкономим памяти
crastinus,
10 Ноября 2013
-
+131
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
try
{
m = (int)Convert.ToInt32(num[1]);
}
catch
{
Console.WriteLine("Invalid parametr");
return true;
}
//...................................................
try
{
matrix[i, j] = (float)Convert.ToDouble(num[j]);
}
catch
{
Console.WriteLine("Invalid matrix");
return false;
}
Лаба одногруника...
Michigan,
09 Ноября 2013
-
+153
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
// Высота шрифта
$lenHdr = mb_strlen( strip_tags($header), 'UTF-8');
$maxDefaultStrLen = 38; // максимальное количество символов при заданном размере шрифта
$maxFontSize = 22; // заданный размер шрифта
$fontSize = $maxFontSize;
if ( $lenHdr > $maxDefaultStrLen ) {
$k = ceil(sqrt(($lenHdr - $maxDefaultStrLen) + 0.25) - 0.5) + 2 ;
$k = ($k<3)? 3:$k;
$fontSize = $maxFontSize - ($k - 2)*2;
$fontSize = ($fontSize<12)? 12:$fontSize;
}
Вот. Откопалось
bot,
08 Ноября 2013
-
+18
- 1
- 2
- 3
- 4
- 5
- 6
- 7
std::string MetaInfo::SetField() {
return m_value;
}
/* ... */
std::string value = meta.SetValue();
Йода-стайл. Переменную эту, хочешь установить ты.
JeremyW,
08 Ноября 2013
-
+161
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
this.ShowHideNoticeDate = function () {
if ($("#associateNotice").is(':checked')) {
jsNoticeField.setFieldValue(1);
$("#associateNotice").parent().parent().parent().parent().parent().parent().next().show();
$("#associateNotice").parent().parent().parent().parent().parent().parent().next().children(1).children(0).children(0).children(0).children(0).children(0).children(1).val("");
} else {
jsNoticeField.setFieldValue(0);
$("#associateNotice").parent().parent().parent().parent().parent().parent().next().hide();
$("#associateNotice").parent().parent().parent().parent().parent().parent().next().children(1).children(0).children(0).children(0).children(0).children(0).children(1).val("");
}
};
Голландский джаваскриптик)))
RomashkaPro,
08 Ноября 2013
-
+134
- 1
- 2
- 3
- 4
- 5
- 6
- 7
int t, max, x;
scanf("%d", &x);
for(t=x%10; max!=t; max=t);
for(t=x%100/10; max<t; max=t);
for(t=x%1000/100; max<t; max=t);
for(t=x/1000; max<t; max=t);
printf("Max: %d\n", max);
Нахождение максимальной цифры в 4-значном числе. Одна из первых лаб по Си. Предполагалось использование if, но студенты не ищут лёгких путей. (Сдвиги они пока не учили, так что на вычисление цифры не обращайте внимания.)
proDOOMman,
07 Ноября 2013
-
+68
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
public static AstRoot parse (String code) {
CompilerEnvirons env = new CompilerEnvirons();
env.setRecoverFromErrors(true);
env.setGenerateDebugInfo(true);
env.setRecordingComments(true);
// try to ignore errors - does not seem to work
env.setIdeMode(true);
IRFactory factory = new IRFactory(env);
AstRoot root = factory.parse(code, null, 0);
// work around rhino bug 800616 (not fixed in neither rhino nor closure)
root.visit(new NodeVisitor() {
@Override
public boolean visit(AstNode node) {
if (node instanceof NumberLiteral) {
NumberLiteral num = (NumberLiteral)node;
int from = num.getAbsolutePosition();
int to = from + num.getLength() + 2;
if (to < code.length()) {
String hex = "0x" + num.toSource();
if (code.substring(from, to).equals(hex)) {
// reset node value and length
num.setValue(hex); num.setLength(hex.length());
}
}
return false;
}
return true;
}
});
// work around rhino SwitchStatement.toSource() bug with empty switches
// https://github.com/mozilla/rhino/blob/master/src/org/mozilla/javascript/ast/SwitchStatement.java#L96
// https://github.com/mozilla/rhino/blob/master/src/org/mozilla/javascript/ast/SwitchStatement.java#L107-L109
// https://github.com/mozilla/rhino/blob/master/src/org/mozilla/javascript/ast/SwitchStatement.java#L158
root.visit(new NodeVisitor() {
@Override
public boolean visit(AstNode node) {
if (node instanceof SwitchStatement) {
SwitchStatement ss = (SwitchStatement)node;
if (ss.getCases().isEmpty()) {
// need to add at least one node to make ss.cases non-null
ArrayList<SwitchCase> cases = new ArrayList<>();
cases.add(new SwitchCase());
ss.setCases(cases);
// set this back to empty list
cases.clear();
ss.setCases(cases);
}
return false;
}
return true;
}
});
return root;
}
И ещё немножко трудовыебуднев пользователей рино: правда клёво взять и распарсить джаваскрипт одним простым методом? Авотхуй.
makc3d,
07 Ноября 2013
-
+70
- 001
- 002
- 003
- 004
- 005
- 006
- 007
- 008
- 009
- 010
- 011
- 012
- 013
- 014
- 015
- 016
- 017
- 018
- 019
- 020
- 021
- 022
- 023
- 024
- 025
- 026
- 027
- 028
- 029
- 030
- 031
- 032
- 033
- 034
- 035
- 036
- 037
- 038
- 039
- 040
- 041
- 042
- 043
- 044
- 045
- 046
- 047
- 048
- 049
- 050
- 051
- 052
- 053
- 054
- 055
- 056
- 057
- 058
- 059
- 060
- 061
- 062
- 063
- 064
- 065
- 066
- 067
- 068
- 069
- 070
- 071
- 072
- 073
- 074
- 075
- 076
- 077
- 078
- 079
- 080
- 081
- 082
- 083
- 084
- 085
- 086
- 087
- 088
- 089
- 090
- 091
- 092
- 093
- 094
- 095
- 096
- 097
- 098
- 099
- 100
public static void replaceChild (AstNode parent, AstNode child, AstNode newChild) {
try {
parent.replaceChild(child, newChild)
} catch (NullPointerException e1) {
// this is one of those shitty nodes with default children handling broken
try {
// maybe it was assignment
Assignment ass = (Assignment)parent
if (ass.left == child) {
ass.left = newChild
} else {
ass.right = newChild
}
} catch (Throwable e2) {
// not assignment :S
try {
// maybe it's (...)
ParenthesizedExpression pae = (ParenthesizedExpression)parent
pae.expression = newChild
} catch (Throwable e3) {
// not (...) either :S
try {
// Function call?
FunctionCall fuc = (FunctionCall)parent
for (int i = 0; i < fuc.arguments.size(); i++) {
if (fuc.arguments.get(i) == child) {
fuc.arguments.set(i, newChild)
break;
}
}
} catch (Throwable e4) {
try {
// Expression statement?
ExpressionStatement est = (ExpressionStatement)parent
est.expression = newChild
} catch (Throwable e5) {
try {
// var foo = bar?
VariableInitializer vin = (VariableInitializer)parent
if (vin.initializer == child) {
vin.initializer = newChild
} else {
// should not happen in our useage
vin.target = newChild
}
} catch (Throwable e6) {
try {
// what if?
IfStatement ifs = (IfStatement)parent
if (ifs.condition == child) {
ifs.condition = newChild
} else if (ifs.thenPart == child) {
ifs.thenPart = newChild
} else {
ifs.elsePart = newChild
}
} catch (Throwable e7) {
try {
// while loop?
WhileLoop whl = (WhileLoop)parent
if (whl.condition == child) {
whl.condition = newChild
} else {
whl.body = newChild
}
} catch (Throwable e8) {
try {
// Infix expression?
InfixExpression iex = (InfixExpression)parent
if (iex.left == child) {
iex.left = newChild
} else {
iex.right = newChild
}
} catch (Throwable e9) {
try {
// do loop?
DoLoop dol = (DoLoop)parent
if (dol.condition == child) {
dol.condition = newChild
} else {
dol.body = newChild
}
} catch (Throwable e10) {
try {
// for loop?
ForLoop fol = (ForLoop)parent
if (fol.condition == child) {
fol.condition = newChild
} else if (fol.initializer == child) {
fol.initializer = newChild
} else if (fol.increment == child) {
fol.increment = newChild
} else {
fol.body = newChild
}
} catch (Throwable e11) {
try {
ConditionalExpression cex = (ConditionalExpression)parent
if (cex.testExpression == child) {
Есть такой жавоскриптопарсер рино. И есть в нём замечательный метод replaceChild, который заменяет в AstNode одного ребёнка другим. Вот только в большей части наследников AstNode он сломан нах.
(пс нету ; ибо груви)
makc3d,
07 Ноября 2013
-
−152
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
protected function get_resource_getter(xml:XML,name:String):Function {
try {
var getter:Function = this["get_"+name+"_xml"] as Function;
return function():int{ return getter(xml)};
} catch (e:*) {}
if(xml.attribute(name).length()==0){
return null;
}
return function():int{ return get_resource_xml(xml,name)};
}
Задача стояла предельно простая: получить количество некоторого игрового ресурса.
Автор подошел к решению неординарно.
strax,
07 Ноября 2013