test cases
This commit is contained in:
@@ -8,8 +8,10 @@ import com.github.gumtreediff.tree.ITree;
|
||||
import edu.lu.uni.serval.utils.ListSorter;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -46,9 +48,9 @@ public class HierarchicalRegrouperForC {
|
||||
*/
|
||||
HierarchicalActionSet actionSet = null;
|
||||
for(Action act : actions){
|
||||
if(act.getNode().getType() == 19 && act.getNode().getLabel().equals("")){
|
||||
continue;
|
||||
}
|
||||
// if(act.getNode().getType() == 19 && act.getNode().getLabel().equals("")){
|
||||
// continue;
|
||||
// }
|
||||
Action parentAct = findParentAction(act, actions);
|
||||
|
||||
if (parentAct == null) {
|
||||
@@ -122,6 +124,27 @@ public class HierarchicalRegrouperForC {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<HierarchicalActionSet> postOrder(HierarchicalActionSet a) {
|
||||
List<HierarchicalActionSet> trees = new ArrayList<>();
|
||||
getAllSubActions(a, trees);
|
||||
return trees;
|
||||
}
|
||||
private void getAllSubActions(HierarchicalActionSet a,List<HierarchicalActionSet> as) {
|
||||
|
||||
List<HierarchicalActionSet> subActions = a.getSubActions();
|
||||
if (subActions.size() != 0){
|
||||
for (HierarchicalActionSet s : subActions) {
|
||||
getAllSubActions(s, as);
|
||||
}
|
||||
|
||||
}
|
||||
as.add(a);
|
||||
// List<HierarchicalActionSet> b = new ArrayList<HierarchicalActionSet>();
|
||||
// for (HierarchicalActionSet child: this.getSubActions())
|
||||
// b.add(child);
|
||||
// return b;
|
||||
}
|
||||
|
||||
private HierarchicalActionSet removeParentNode(HierarchicalActionSet actionSet){
|
||||
List<HierarchicalActionSet> subActions = actionSet.getSubActions();
|
||||
Action action = actionSet.getAction();
|
||||
@@ -143,9 +166,16 @@ public class HierarchicalRegrouperForC {
|
||||
|
||||
private HierarchicalActionSet removeBlocks(HierarchicalActionSet actionSet){
|
||||
List<HierarchicalActionSet> subActions = actionSet.getSubActions();
|
||||
Predicate<HierarchicalActionSet> predicate = x->NodeMap_new.getKeysByValue(NodeMap_new.StatementMap,x.getAstNodeType()).size() == 1 ;
|
||||
Predicate<HierarchicalActionSet> predicate1 = x->!x.getAstNodeType().equals("block");
|
||||
|
||||
|
||||
Action action = actionSet.getAction();
|
||||
if (subActions.size() == 1){
|
||||
HierarchicalActionSet subaction = subActions.get(0);
|
||||
if(!postOrder(subaction).stream().anyMatch(predicate.and(predicate1))){
|
||||
return actionSet;
|
||||
}
|
||||
Action action1 = subaction.getAction();
|
||||
//else,then,block
|
||||
if(action.getClass().equals(action1.getClass()) && action.getName().equals("UPD")) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,6 +1,7 @@
|
||||
package edu.lu.uni.serval.fixminer.ediff;
|
||||
|
||||
import com.github.gumtreediff.tree.ITree;
|
||||
import edu.lu.uni.serval.utils.CallShell;
|
||||
import edu.lu.uni.serval.utils.EDiffHelper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -20,18 +21,18 @@ public class TestRealCases {
|
||||
public void test_287_A_14208510_14208532() throws IOException {
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("287-A-14208510-14208532.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD block@@ if g ][i ][j == '.' d ++ else h ++ if g ][i ][j + 1 == '.' d ++ else h ++ if g ][i + 1 ][j == '.' d ++ else h ++ if g ][i + 1 ][j + 1 == '.' d ++ else h ++ if d == 3 || h == 3 printf \"YES\" 0 @TO@ if g ][i ][j == '.' d ++ else h ++ if g ][i ][j + 1 == '.' d ++ else h ++ if g ][i + 1 ][j == '.' d ++ else h ++ if g ][i + 1 ][j + 1 == '.' d ++ else h ++ if d >= 3 || h >= 3 printf \"YES\" 0 d = 0 h = 0 @AT@ 199 @LENGTH@ 347\n" +
|
||||
"---UPD if@@if d == 3 || h == 3 printf \"YES\" 0 @TO@ if d >= 3 || h >= 3 printf \"YES\" 0 @AT@ 449 @LENGTH@ 37\n" +
|
||||
"------UPD condition@@ d == 3 || h == 3 @TO@ d >= 3 || h >= 3 @AT@ 449 @LENGTH@ 15\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD block@@if g ][i ][j == '.' d ++ else h ++ if g ][i ][j + 1 == '.' d ++ else h ++ if g ][i + 1 ][j == '.' d ++ else h ++ if g ][i + 1 ][j + 1 == '.' d ++ else h ++ if d == 3 || h == 3 printf \"YES\" return 0 @TO@ if g ][i ][j == '.' d ++ else h ++ if g ][i ][j + 1 == '.' d ++ else h ++ if g ][i + 1 ][j == '.' d ++ else h ++ if g ][i + 1 ][j + 1 == '.' d ++ else h ++ if d >= 3 || h >= 3 printf \"YES\" return 0 d = 0 h = 0 @AT@ 199 @LENGTH@ 197\n" +
|
||||
"---UPD if@@if d == 3 || h == 3 printf \"YES\" return 0 @TO@ if d >= 3 || h >= 3 printf \"YES\" return 0 @AT@ 449 @LENGTH@ 41\n" +
|
||||
"------UPD condition@@d == 3 || h == 3 @TO@ d >= 3 || h >= 3 @AT@ 449 @LENGTH@ 16\n" +
|
||||
"---------UPD expr@@d == 3 || h == 3 @TO@ d >= 3 || h >= 3 @AT@ 450 @LENGTH@ 16\n" +
|
||||
"------------UPD operator@@== @TO@ >= @AT@ 451 @LENGTH@ 2\n" +
|
||||
"------------UPD operator@@== @TO@ >= @AT@ 459 @LENGTH@ 2\n" +
|
||||
"---INS expr_stmt@@d = 0 @TO@ block@@ if g ][i ][j == '.' d ++ else h ++ if g ][i ][j + 1 == '.' d ++ else h ++ if g ][i + 1 ][j == '.' d ++ else h ++ if g ][i + 1 ][j + 1 == '.' d ++ else h ++ if d == 3 || h == 3 printf \"YES\" 0 @AT@ 548 @LENGTH@ 5\n" +
|
||||
"---INS expr_stmt@@d = 0 @TO@ block@@if g ][i ][j == '.' d ++ else h ++ if g ][i ][j + 1 == '.' d ++ else h ++ if g ][i + 1 ][j == '.' d ++ else h ++ if g ][i + 1 ][j + 1 == '.' d ++ else h ++ if d == 3 || h == 3 printf \"YES\" return 0 @AT@ 548 @LENGTH@ 5\n" +
|
||||
"------INS expr@@d = 0 @TO@ expr_stmt@@d = 0 @AT@ 548 @LENGTH@ 5\n" +
|
||||
"---------INS name@@d @TO@ expr@@d = 0 @AT@ 548 @LENGTH@ 1\n" +
|
||||
"---------INS operator@@= @TO@ expr@@d = 0 @AT@ 549 @LENGTH@ 1\n" +
|
||||
"---------INS literal@@0 @TO@ expr@@d = 0 @AT@ 550 @LENGTH@ 1\n" +
|
||||
"---INS expr_stmt@@h = 0 @TO@ block@@ if g ][i ][j == '.' d ++ else h ++ if g ][i ][j + 1 == '.' d ++ else h ++ if g ][i + 1 ][j == '.' d ++ else h ++ if g ][i + 1 ][j + 1 == '.' d ++ else h ++ if d == 3 || h == 3 printf \"YES\" 0 @AT@ 553 @LENGTH@ 5\n" +
|
||||
"---INS expr_stmt@@h = 0 @TO@ block@@if g ][i ][j == '.' d ++ else h ++ if g ][i ][j + 1 == '.' d ++ else h ++ if g ][i + 1 ][j == '.' d ++ else h ++ if g ][i + 1 ][j + 1 == '.' d ++ else h ++ if d == 3 || h == 3 printf \"YES\" return 0 @AT@ 553 @LENGTH@ 5\n" +
|
||||
"------INS expr@@h = 0 @TO@ expr_stmt@@h = 0 @AT@ 553 @LENGTH@ 5\n" +
|
||||
"---------INS name@@h @TO@ expr@@h = 0 @AT@ 553 @LENGTH@ 1\n" +
|
||||
"---------INS operator@@= @TO@ expr@@h = 0 @AT@ 554 @LENGTH@ 1\n" +
|
||||
@@ -63,11 +64,11 @@ public class TestRealCases {
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("189-B-1682083-1682218.c");
|
||||
// Assert.assertFalse(true);
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD expr_stmt@@k = MIN k h - j @TO@ t = MIN t h - j @AT@ 254 @LENGTH@ 16\n" +
|
||||
"---UPD expr@@k = MIN k h - j @TO@ t = MIN t h - j @AT@ 254 @LENGTH@ 16\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD expr_stmt@@k = MIN k h - j @TO@ t = MIN t h - j @AT@ 254 @LENGTH@ 15\n" +
|
||||
"---UPD expr@@k = MIN k h - j @TO@ t = MIN t h - j @AT@ 254 @LENGTH@ 15\n" +
|
||||
"------UPD name@@k @TO@ t @AT@ 254 @LENGTH@ 1\n" +
|
||||
"------UPD call@@MIN k h - j @TO@ MIN t h - j @AT@ 258 @LENGTH@ 12\n" +
|
||||
"---------UPD argument_list@@ k h - j @TO@ t h - j @AT@ 261 @LENGTH@ 11\n" +
|
||||
"------UPD call@@MIN k h - j @TO@ MIN t h - j @AT@ 258 @LENGTH@ 11\n" +
|
||||
"---------UPD argument_list@@k h - j @TO@ t h - j @AT@ 261 @LENGTH@ 7\n" +
|
||||
"------------UPD argument@@k @TO@ t @AT@ 262 @LENGTH@ 1\n" +
|
||||
"---------------UPD expr@@k @TO@ t @AT@ 262 @LENGTH@ 1\n" +
|
||||
"------------------UPD name@@k @TO@ t @AT@ 262 @LENGTH@ 1\n");
|
||||
@@ -80,7 +81,7 @@ public class TestRealCases {
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("177-A2-1594730-1595168.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD if@@if i == ( n - 1 ) / 2 && j == ( n - 1 ) / 2 mid = a @TO@ if i == ( n + 1 ) / 2 && j == ( n + 1 ) / 2 mid = a @AT@ 350 @LENGTH@ 51\n" +
|
||||
"---UPD condition@@ i == ( n - 1 ) / 2 && j == ( n - 1 ) / 2 @TO@ i == ( n + 1 ) / 2 && j == ( n + 1 ) / 2 @AT@ 350 @LENGTH@ 27\n" +
|
||||
"---UPD condition@@i == ( n - 1 ) / 2 && j == ( n - 1 ) / 2 @TO@ i == ( n + 1 ) / 2 && j == ( n + 1 ) / 2 @AT@ 350 @LENGTH@ 40\n" +
|
||||
"------UPD expr@@i == ( n - 1 ) / 2 && j == ( n - 1 ) / 2 @TO@ i == ( n + 1 ) / 2 && j == ( n + 1 ) / 2 @AT@ 351 @LENGTH@ 40\n" +
|
||||
"---------UPD operator@@- @TO@ + @AT@ 356 @LENGTH@ 1\n" +
|
||||
"---------UPD operator@@- @TO@ + @AT@ 370 @LENGTH@ 1\n");
|
||||
@@ -123,7 +124,7 @@ public class TestRealCases {
|
||||
//TODO not sure
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("197-B-18221952-18221968.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"INS expr_stmt@@i -- @TO@ block@@ a ][0 /= i b ][0 /= i @AT@ 831 @LENGTH@ 4\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"INS expr_stmt@@i -- @TO@ block@@a ][0 /= i b ][0 /= i @AT@ 831 @LENGTH@ 4\n" +
|
||||
"---INS expr@@i -- @TO@ expr_stmt@@i -- @AT@ 831 @LENGTH@ 4\n" +
|
||||
"------INS name@@i @TO@ expr@@i -- @AT@ 831 @LENGTH@ 1\n" +
|
||||
"------INS operator@@-- @TO@ expr@@i -- @AT@ 832 @LENGTH@ 2\n");
|
||||
@@ -134,8 +135,8 @@ public class TestRealCases {
|
||||
public void test_474_A_15226851_15226912() throws IOException {
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("474-A-15226851-15226912.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD block@@ str ][i = s ][j + 1 @TO@ j ++ str ][i = s ][j @AT@ 560 @LENGTH@ 55\n" +
|
||||
"---INS expr_stmt@@j ++ @TO@ block@@ str ][i = s ][j + 1 @AT@ 582 @LENGTH@ 4\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD block@@str ][i = s ][j + 1 @TO@ j ++ str ][i = s ][j @AT@ 560 @LENGTH@ 19\n" +
|
||||
"---INS expr_stmt@@j ++ @TO@ block@@str ][i = s ][j + 1 @AT@ 582 @LENGTH@ 4\n" +
|
||||
"------INS expr@@j ++ @TO@ expr_stmt@@j ++ @AT@ 582 @LENGTH@ 4\n" +
|
||||
"---------INS name@@j @TO@ expr@@j ++ @AT@ 582 @LENGTH@ 1\n" +
|
||||
"---------INS operator@@++ @TO@ expr@@j ++ @AT@ 583 @LENGTH@ 2\n" +
|
||||
@@ -154,7 +155,7 @@ public class TestRealCases {
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("469-B-8248222-8248281.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD if@@if temp1 < r && temp2 > l for k = temp1 k <= temp2 k ++ t ][k = 1 @TO@ if temp1 <= r && temp2 >= l for k = temp1 k <= temp2 k ++ t ][k = 1 @AT@ 432 @LENGTH@ 65\n" +
|
||||
"---UPD condition@@ temp1 < r && temp2 > l @TO@ temp1 <= r && temp2 >= l @AT@ 432 @LENGTH@ 19\n" +
|
||||
"---UPD condition@@temp1 < r && temp2 > l @TO@ temp1 <= r && temp2 >= l @AT@ 432 @LENGTH@ 22\n" +
|
||||
"------UPD expr@@temp1 < r && temp2 > l @TO@ temp1 <= r && temp2 >= l @AT@ 433 @LENGTH@ 22\n" +
|
||||
"---------UPD operator@@< @TO@ <= @AT@ 438 @LENGTH@ 1\n" +
|
||||
"---------UPD operator@@> @TO@ >= @AT@ 447 @LENGTH@ 1\n");
|
||||
@@ -165,8 +166,8 @@ public class TestRealCases {
|
||||
public void test_189_B_17295034_17295064() throws IOException {
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("189-B-17295034-17295064.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD for@@for b = 2 b <= w b += 2 count += ( w - a + 1 ) * ( h - b + 1 ) @TO@ for b = 2 b <= h b += 2 count += ( w - a + 1 ) * ( h - b + 1 ) @AT@ 183 @LENGTH@ 63\n" +
|
||||
"---UPD control@@ b = 2 b <= w b += 2 @TO@ b = 2 b <= h b += 2 @AT@ 183 @LENGTH@ 16\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD for@@for b = 2 b <= w b += 2 count += ( w - a + 1 ) * ( h - b + 1 ) @TO@ for b = 2 b <= h b += 2 count += ( w - a + 1 ) * ( h - b + 1 ) @AT@ 183 @LENGTH@ 62\n" +
|
||||
"---UPD control@@b = 2 b <= w b += 2 @TO@ b = 2 b <= h b += 2 @AT@ 183 @LENGTH@ 19\n" +
|
||||
"------UPD condition@@b <= w @TO@ b <= h @AT@ 188 @LENGTH@ 6\n" +
|
||||
"---------UPD expr@@b <= w @TO@ b <= h @AT@ 188 @LENGTH@ 6\n" +
|
||||
"------------UPD name@@w @TO@ h @AT@ 191 @LENGTH@ 1\n");
|
||||
@@ -178,21 +179,21 @@ public class TestRealCases {
|
||||
//TODO not sure
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("244-B-5291533-5291541.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"INS elseif@@elseif if a == 784262 printf \"4079\\n\" @TO@ if@@if a <= 101 printf \"%d\\n\" a elseif if a == 123 printf \"113\\n\" elseif if a == 1000 printf \"352\\n\" elseif if a == 1000000000 printf \"40744\\n\" elseif if a == 999999999 printf \"40743\\n\" elseif if a == 999999998 printf \"40742\\n\" elseif if a == 999999997 printf \"40741\\n\" elseif if a == 909090901 printf \"38532\\n\" elseif if a == 142498040 printf \"21671\\n\" elseif if a == 603356456 printf \"31623\\n\" elseif if a == 64214872 printf \"15759\\n\" elseif if a == 820040584 printf \"36407\\n\" elseif if a == 442198 printf \"3071\\n\" elseif if a == 642678 printf \"3615\\n\" elseif if a == 468390 printf \"3223\\n\" elseif if a == 326806 printf \"2759\\n\" elseif if a == 940 printf \"331\\n\" elseif if a == 356 printf \"175\\n\" elseif if a == 132 printf \"114\\n\" elseif if a == 102 printf \"101\\n\" @AT@ 877 @LENGTH@ 38\n" +
|
||||
"---INS if@@if a == 784262 printf \"4079\\n\" @TO@ elseif@@elseif if a == 784262 printf \"4079\\n\" @AT@ 877 @LENGTH@ 31\n" +
|
||||
"------INS condition@@ a == 784262 @TO@ if@@if a == 784262 printf \"4079\\n\" @AT@ 877 @LENGTH@ 12\n" +
|
||||
"---------INS expr@@a == 784262 @TO@ condition@@ a == 784262 @AT@ 878 @LENGTH@ 11\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"INS elseif@@elseif if a == 784262 printf \"4079\\n\" @TO@ if@@if a <= 101 printf \"%d\\n\" a elseif if a == 123 printf \"113\\n\" elseif if a == 1000 printf \"352\\n\" elseif if a == 1000000000 printf \"40744\\n\" elseif if a == 999999999 printf \"40743\\n\" elseif if a == 999999998 printf \"40742\\n\" elseif if a == 999999997 printf \"40741\\n\" elseif if a == 909090901 printf \"38532\\n\" elseif if a == 142498040 printf \"21671\\n\" elseif if a == 603356456 printf \"31623\\n\" elseif if a == 64214872 printf \"15759\\n\" elseif if a == 820040584 printf \"36407\\n\" elseif if a == 442198 printf \"3071\\n\" elseif if a == 642678 printf \"3615\\n\" elseif if a == 468390 printf \"3223\\n\" elseif if a == 326806 printf \"2759\\n\" elseif if a == 940 printf \"331\\n\" elseif if a == 356 printf \"175\\n\" elseif if a == 132 printf \"114\\n\" elseif if a == 102 printf \"101\\n\" @AT@ 877 @LENGTH@ 37\n" +
|
||||
"---INS if@@if a == 784262 printf \"4079\\n\" @TO@ elseif@@elseif if a == 784262 printf \"4079\\n\" @AT@ 877 @LENGTH@ 30\n" +
|
||||
"------INS condition@@a == 784262 @TO@ if@@if a == 784262 printf \"4079\\n\" @AT@ 877 @LENGTH@ 11\n" +
|
||||
"---------INS expr@@a == 784262 @TO@ condition@@a == 784262 @AT@ 878 @LENGTH@ 11\n" +
|
||||
"------------INS name@@a @TO@ expr@@a == 784262 @AT@ 878 @LENGTH@ 1\n" +
|
||||
"------------INS operator@@== @TO@ expr@@a == 784262 @AT@ 879 @LENGTH@ 2\n" +
|
||||
"------------INS literal@@784262 @TO@ expr@@a == 784262 @AT@ 881 @LENGTH@ 6\n" +
|
||||
"------INS then@@printf \"4079\\n\" @TO@ if@@if a == 784262 printf \"4079\\n\" @AT@ 901 @LENGTH@ 16\n" +
|
||||
"---------INS block@@printf \"4079\\n\" @TO@ then@@printf \"4079\\n\" @AT@ 901 @LENGTH@ 16\n" +
|
||||
"------------INS expr_stmt@@printf \"4079\\n\" @TO@ block@@printf \"4079\\n\" @AT@ 901 @LENGTH@ 16\n" +
|
||||
"---------------INS expr@@printf \"4079\\n\" @TO@ expr_stmt@@printf \"4079\\n\" @AT@ 901 @LENGTH@ 16\n" +
|
||||
"------------------INS call@@printf \"4079\\n\" @TO@ expr@@printf \"4079\\n\" @AT@ 901 @LENGTH@ 16\n" +
|
||||
"---------------------INS name@@printf @TO@ call@@printf \"4079\\n\" @AT@ 901 @LENGTH@ 6\n" +
|
||||
"---------------------INS argument_list@@ \"4079\\n\" @TO@ call@@printf \"4079\\n\" @AT@ 907 @LENGTH@ 11\n" +
|
||||
"------------------------INS argument@@\"4079\\n\" @TO@ argument_list@@ \"4079\\n\" @AT@ 908 @LENGTH@ 8\n" +
|
||||
"------INS then@@printf \"4079\\n\" @TO@ if@@if a == 784262 printf \"4079\\n\" @AT@ 901 @LENGTH@ 15\n" +
|
||||
"---------INS block@@printf \"4079\\n\" @TO@ then@@printf \"4079\\n\" @AT@ 901 @LENGTH@ 15\n" +
|
||||
"------------INS expr_stmt@@printf \"4079\\n\" @TO@ block@@printf \"4079\\n\" @AT@ 901 @LENGTH@ 15\n" +
|
||||
"---------------INS expr@@printf \"4079\\n\" @TO@ expr_stmt@@printf \"4079\\n\" @AT@ 901 @LENGTH@ 15\n" +
|
||||
"------------------INS call@@printf \"4079\\n\" @TO@ expr@@printf \"4079\\n\" @AT@ 901 @LENGTH@ 15\n" +
|
||||
"---------------------INS name@@printf @TO@ call@@printf \"4079\\n\" @AT@ 901 @LENGTH@ 6\n" +
|
||||
"---------------------INS argument_list@@\"4079\\n\" @TO@ call@@printf \"4079\\n\" @AT@ 907 @LENGTH@ 8\n" +
|
||||
"------------------------INS argument@@\"4079\\n\" @TO@ argument_list@@\"4079\\n\" @AT@ 908 @LENGTH@ 8\n" +
|
||||
"---------------------------INS expr@@\"4079\\n\" @TO@ argument@@\"4079\\n\" @AT@ 908 @LENGTH@ 8\n" +
|
||||
"------------------------------INS literal@@\"4079\\n\" @TO@ expr@@\"4079\\n\" @AT@ 908 @LENGTH@ 8\n");
|
||||
|
||||
@@ -201,29 +202,29 @@ public class TestRealCases {
|
||||
public void test_166_C_1395587_1395933() throws IOException {
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("166-C-1395587-1395933.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD if@@if array ][( n + 1 ) / 2 == x printf \"0\\n\" elseif if last < ( n + 1 ) / 2 printf \"%d\\n\" n - 2 * last elseif if first > ( n + 1 ) / 2 printf \"%d\\n\" 2 * first - n - 1 @TO@ if array ][( n + 1 ) / 2 - 1 == x printf \"0\\n\" elseif if last < ( n + 1 ) / 2 printf \"%d\\n\" n - 2 * last elseif if first > ( n + 1 ) / 2 printf \"%d\\n\" 2 * first - n - 1 elseif if n == 1 printf \"0\\n\" @AT@ 771 @LENGTH@ 167\n" +
|
||||
"---UPD condition@@ array ][( n + 1 ) / 2 == x @TO@ array ][( n + 1 ) / 2 - 1 == x @AT@ 771 @LENGTH@ 20\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD if@@if array ][( n + 1 ) / 2 == x printf \"0\\n\" elseif if last < ( n + 1 ) / 2 printf \"%d\\n\" n - 2 * last elseif if first > ( n + 1 ) / 2 printf \"%d\\n\" 2 * first - n - 1 @TO@ if array ][( n + 1 ) / 2 - 1 == x printf \"0\\n\" elseif if last < ( n + 1 ) / 2 printf \"%d\\n\" n - 2 * last elseif if first > ( n + 1 ) / 2 printf \"%d\\n\" 2 * first - n - 1 elseif if n == 1 printf \"0\\n\" @AT@ 771 @LENGTH@ 164\n" +
|
||||
"---UPD condition@@array ][( n + 1 ) / 2 == x @TO@ array ][( n + 1 ) / 2 - 1 == x @AT@ 771 @LENGTH@ 26\n" +
|
||||
"------UPD expr@@array ][( n + 1 ) / 2 == x @TO@ array ][( n + 1 ) / 2 - 1 == x @AT@ 772 @LENGTH@ 26\n" +
|
||||
"---------UPD name@@array ][( n + 1 ) / 2 @TO@ array ][( n + 1 ) / 2 - 1 @AT@ 772 @LENGTH@ 21\n" +
|
||||
"------------UPD index@@][( n + 1 ) / 2 @TO@ ][( n + 1 ) / 2 - 1 @AT@ 778 @LENGTH@ 15\n" +
|
||||
"---------------UPD expr@@[( n + 1 ) / 2 @TO@ [( n + 1 ) / 2 - 1 @AT@ 778 @LENGTH@ 14\n" +
|
||||
"------------------INS operator@@- @TO@ expr@@[( n + 1 ) / 2 @AT@ 785 @LENGTH@ 1\n" +
|
||||
"------------------INS literal@@1 @TO@ expr@@[( n + 1 ) / 2 @AT@ 786 @LENGTH@ 1\n" +
|
||||
"---INS elseif@@elseif if n == 1 printf \"0\\n\" @TO@ if@@if array ][( n + 1 ) / 2 == x printf \"0\\n\" elseif if last < ( n + 1 ) / 2 printf \"%d\\n\" n - 2 * last elseif if first > ( n + 1 ) / 2 printf \"%d\\n\" 2 * first - n - 1 @AT@ 925 @LENGTH@ 30\n" +
|
||||
"------INS if@@if n == 1 printf \"0\\n\" @TO@ elseif@@elseif if n == 1 printf \"0\\n\" @AT@ 925 @LENGTH@ 23\n" +
|
||||
"---------INS condition@@ n == 1 @TO@ if@@if n == 1 printf \"0\\n\" @AT@ 925 @LENGTH@ 7\n" +
|
||||
"------------INS expr@@n == 1 @TO@ condition@@ n == 1 @AT@ 926 @LENGTH@ 6\n" +
|
||||
"---INS elseif@@elseif if n == 1 printf \"0\\n\" @TO@ if@@if array ][( n + 1 ) / 2 == x printf \"0\\n\" elseif if last < ( n + 1 ) / 2 printf \"%d\\n\" n - 2 * last elseif if first > ( n + 1 ) / 2 printf \"%d\\n\" 2 * first - n - 1 @AT@ 925 @LENGTH@ 29\n" +
|
||||
"------INS if@@if n == 1 printf \"0\\n\" @TO@ elseif@@elseif if n == 1 printf \"0\\n\" @AT@ 925 @LENGTH@ 22\n" +
|
||||
"---------INS condition@@n == 1 @TO@ if@@if n == 1 printf \"0\\n\" @AT@ 925 @LENGTH@ 6\n" +
|
||||
"------------INS expr@@n == 1 @TO@ condition@@n == 1 @AT@ 926 @LENGTH@ 6\n" +
|
||||
"---------------INS name@@n @TO@ expr@@n == 1 @AT@ 926 @LENGTH@ 1\n" +
|
||||
"---------------INS operator@@== @TO@ expr@@n == 1 @AT@ 927 @LENGTH@ 2\n" +
|
||||
"---------------INS literal@@1 @TO@ expr@@n == 1 @AT@ 929 @LENGTH@ 1\n" +
|
||||
"---------INS then@@printf \"0\\n\" @TO@ if@@if n == 1 printf \"0\\n\" @AT@ 932 @LENGTH@ 13\n" +
|
||||
"------------INS block@@printf \"0\\n\" @TO@ then@@printf \"0\\n\" @AT@ 932 @LENGTH@ 13\n" +
|
||||
"---------------INS expr_stmt@@printf \"0\\n\" @TO@ block@@printf \"0\\n\" @AT@ 932 @LENGTH@ 13\n" +
|
||||
"------------------INS expr@@printf \"0\\n\" @TO@ expr_stmt@@printf \"0\\n\" @AT@ 932 @LENGTH@ 13\n" +
|
||||
"---------------------INS call@@printf \"0\\n\" @TO@ expr@@printf \"0\\n\" @AT@ 932 @LENGTH@ 13\n" +
|
||||
"------------------------INS name@@printf @TO@ call@@printf \"0\\n\" @AT@ 932 @LENGTH@ 6\n" +
|
||||
"------------------------INS argument_list@@ \"0\\n\" @TO@ call@@printf \"0\\n\" @AT@ 938 @LENGTH@ 8\n" +
|
||||
"---------------------------INS argument@@\"0\\n\" @TO@ argument_list@@ \"0\\n\" @AT@ 939 @LENGTH@ 5\n" +
|
||||
"---------INS then@@printf \"0\\n\" @TO@ if@@if n == 1 printf \"0\\n\" @AT@ 932 @LENGTH@ 12\n" +
|
||||
"------------INS block@@printf \"0\\n\" @TO@ then@@printf \"0\\n\" @AT@ 932 @LENGTH@ 12\n" +
|
||||
"---------------INS expr_stmt@@printf \"0\\n\" @TO@ block@@printf \"0\\n\" @AT@ 932 @LENGTH@ 12\n" +
|
||||
"------------------INS expr@@printf \"0\\n\" @TO@ expr_stmt@@printf \"0\\n\" @AT@ 932 @LENGTH@ 12\n" +
|
||||
"---------------------INS call@@printf \"0\\n\" @TO@ expr@@printf \"0\\n\" @AT@ 932 @LENGTH@ 12\n" +
|
||||
"------------------------INS name@@printf @TO@ call@@printf \"0\\n\" @AT@ 932 @LENGTH@ 6\n" +
|
||||
"------------------------INS argument_list@@\"0\\n\" @TO@ call@@printf \"0\\n\" @AT@ 938 @LENGTH@ 5\n" +
|
||||
"---------------------------INS argument@@\"0\\n\" @TO@ argument_list@@\"0\\n\" @AT@ 939 @LENGTH@ 5\n" +
|
||||
"------------------------------INS expr@@\"0\\n\" @TO@ argument@@\"0\\n\" @AT@ 939 @LENGTH@ 5\n" +
|
||||
"---------------------------------INS literal@@\"0\\n\" @TO@ expr@@\"0\\n\" @AT@ 939 @LENGTH@ 5\n");
|
||||
|
||||
@@ -251,7 +252,7 @@ public class TestRealCases {
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("158-A-18237828-18237840.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD if@@if ara ][i >= ara ][k - 1 count ++ @TO@ if ara ][i >= ara ][k - 1 && ara ][i != 0 count ++ @AT@ 219 @LENGTH@ 34\n" +
|
||||
"---UPD condition@@ ara ][i >= ara ][k - 1 @TO@ ara ][i >= ara ][k - 1 && ara ][i != 0 @AT@ 219 @LENGTH@ 19\n" +
|
||||
"---UPD condition@@ara ][i >= ara ][k - 1 @TO@ ara ][i >= ara ][k - 1 && ara ][i != 0 @AT@ 219 @LENGTH@ 22\n" +
|
||||
"------UPD expr@@ara ][i >= ara ][k - 1 @TO@ ara ][i >= ara ][k - 1 && ara ][i != 0 @AT@ 220 @LENGTH@ 22\n" +
|
||||
"---------INS operator@@&& @TO@ expr@@ara ][i >= ara ][k - 1 @AT@ 236 @LENGTH@ 2\n" +
|
||||
"---------INS name@@ara ][i @TO@ expr@@ara ][i >= ara ][k - 1 @AT@ 239 @LENGTH@ 7\n" +
|
||||
@@ -286,7 +287,7 @@ public class TestRealCases {
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("489-A-9343123-9343126.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD if@@if ZA ][d < ZA ][c d = c @TO@ if ZA ][d > ZA ][c d = c @AT@ 252 @LENGTH@ 24\n" +
|
||||
"---UPD condition@@ ZA ][d < ZA ][c @TO@ ZA ][d > ZA ][c @AT@ 252 @LENGTH@ 16\n" +
|
||||
"---UPD condition@@ZA ][d < ZA ][c @TO@ ZA ][d > ZA ][c @AT@ 252 @LENGTH@ 15\n" +
|
||||
"------UPD expr@@ZA ][d < ZA ][c @TO@ ZA ][d > ZA ][c @AT@ 253 @LENGTH@ 15\n" +
|
||||
"---------UPD operator@@< @TO@ > @AT@ 259 @LENGTH@ 1\n");
|
||||
|
||||
@@ -296,8 +297,8 @@ public class TestRealCases {
|
||||
public void test_143_A_17964626_17964657() throws IOException {
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("143-A-17964626-17964657.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD for@@for a = 1 a < ( r1 % 10 ) a ++ for i = 1 i <= 1000 i ++ ar ][i = 0 ar ][a = 1 if a >= c1 || a >= d1 continue; b = r1 - a if ar ][b == 1 continue; else ar ][b = 1 if b >= c2 || b >= d2 continue; c = c1 - a if ar ][c == 1 continue; else ar ][c = 1 if c >= r2 || c >= d2 continue; d = d1 - a if ar ][d == 1 continue; if d >= r2 || d >= c2 continue; if b + c != d2 continue; if b + d != c2 continue; if c + d != r2 continue; if a > 9 || b > 9 || c > 9 || d > 9 continue; flag = 1 break; @TO@ for a = 1 a < r1 a ++ for i = 1 i <= 1000 i ++ ar ][i = 0 ar ][a = 1 if a >= c1 || a >= d1 continue; b = r1 - a if ar ][b == 1 continue; else ar ][b = 1 if b >= c2 || b >= d2 continue; c = c1 - a if ar ][c == 1 continue; else ar ][c = 1 if c >= r2 || c >= d2 continue; d = d1 - a if ar ][d == 1 continue; if d >= r2 || d >= c2 continue; if b + c != d2 continue; if b + d != c2 continue; if c + d != r2 continue; if a > 9 || b > 9 || c > 9 || d > 9 continue; flag = 1 break; @AT@ 187 @LENGTH@ 487\n" +
|
||||
"---UPD control@@ a = 1 a < ( r1 % 10 ) a ++ @TO@ a = 1 a < r1 a ++ @AT@ 187 @LENGTH@ 22\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD for@@for a = 1 a < ( r1 % 10 ) a ++ for i = 1 i <= 1000 i ++ ar ][i = 0 ar ][a = 1 if a >= c1 || a >= d1 continue; b = r1 - a if ar ][b == 1 continue; else ar ][b = 1 if b >= c2 || b >= d2 continue; c = c1 - a if ar ][c == 1 continue; else ar ][c = 1 if c >= r2 || c >= d2 continue; d = d1 - a if ar ][d == 1 continue; if d >= r2 || d >= c2 continue; if b + c != d2 continue; if b + d != c2 continue; if c + d != r2 continue; if a > 9 || b > 9 || c > 9 || d > 9 continue; flag = 1 break; @TO@ for a = 1 a < r1 a ++ for i = 1 i <= 1000 i ++ ar ][i = 0 ar ][a = 1 if a >= c1 || a >= d1 continue; b = r1 - a if ar ][b == 1 continue; else ar ][b = 1 if b >= c2 || b >= d2 continue; c = c1 - a if ar ][c == 1 continue; else ar ][c = 1 if c >= r2 || c >= d2 continue; d = d1 - a if ar ][d == 1 continue; if d >= r2 || d >= c2 continue; if b + c != d2 continue; if b + d != c2 continue; if c + d != r2 continue; if a > 9 || b > 9 || c > 9 || d > 9 continue; flag = 1 break; @AT@ 187 @LENGTH@ 482\n" +
|
||||
"---UPD control@@a = 1 a < ( r1 % 10 ) a ++ @TO@ a = 1 a < r1 a ++ @AT@ 187 @LENGTH@ 26\n" +
|
||||
"------UPD condition@@a < ( r1 % 10 ) @TO@ a < r1 @AT@ 193 @LENGTH@ 15\n" +
|
||||
"---------UPD expr@@a < ( r1 % 10 ) @TO@ a < r1 @AT@ 193 @LENGTH@ 15\n" +
|
||||
"------------DEL operator@@( @AT@ 195 @LENGTH@ 1\n" +
|
||||
@@ -314,8 +315,8 @@ public class TestRealCases {
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("612-A-15750192-15750273.c");
|
||||
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD for@@for i = p i <= k i ++ printf \"%c\" a ][i @TO@ for i = p i < k i ++ printf \"%c\" a ][i @AT@ 262 @LENGTH@ 41\n" +
|
||||
"---UPD control@@ i = p i <= k i ++ @TO@ i = p i < k i ++ @AT@ 262 @LENGTH@ 15\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD for@@for i = p i <= k i ++ printf \"%c\" a ][i @TO@ for i = p i < k i ++ printf \"%c\" a ][i @AT@ 262 @LENGTH@ 39\n" +
|
||||
"---UPD control@@i = p i <= k i ++ @TO@ i = p i < k i ++ @AT@ 262 @LENGTH@ 17\n" +
|
||||
"------UPD condition@@i <= k @TO@ i < k @AT@ 267 @LENGTH@ 6\n" +
|
||||
"---------UPD expr@@i <= k @TO@ i < k @AT@ 267 @LENGTH@ 6\n" +
|
||||
"------------UPD operator@@<= @TO@ < @AT@ 268 @LENGTH@ 2\n");
|
||||
@@ -327,16 +328,16 @@ public class TestRealCases {
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("344-A-17290259-17290309.c");
|
||||
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD for@@for i = 0 i < n i ++ if a ][i + 1 == a ][i d = d + 1 else f = f + 1 i = i + 2 @TO@ for i = 0 i < n - 1 i ++ if a ][i + 1 == a ][i d = d + 1 else f = f + 1 @AT@ 158 @LENGTH@ 80\n" +
|
||||
"---UPD control@@ i = 0 i < n i ++ @TO@ i = 0 i < n - 1 i ++ @AT@ 158 @LENGTH@ 14\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD for@@for i = 0 i < n i ++ if a ][i + 1 == a ][i d = d + 1 else f = f + 1 i = i + 2 @TO@ for i = 0 i < n - 1 i ++ if a ][i + 1 == a ][i d = d + 1 else f = f + 1 @AT@ 158 @LENGTH@ 77\n" +
|
||||
"---UPD control@@i = 0 i < n i ++ @TO@ i = 0 i < n - 1 i ++ @AT@ 158 @LENGTH@ 16\n" +
|
||||
"------UPD condition@@i < n @TO@ i < n - 1 @AT@ 163 @LENGTH@ 5\n" +
|
||||
"---------UPD expr@@i < n @TO@ i < n - 1 @AT@ 163 @LENGTH@ 5\n" +
|
||||
"------------INS operator@@- @TO@ expr@@i < n @AT@ 166 @LENGTH@ 1\n" +
|
||||
"------------INS literal@@1 @TO@ expr@@i < n @AT@ 167 @LENGTH@ 1\n" +
|
||||
"---UPD block@@ if a ][i + 1 == a ][i d = d + 1 else f = f + 1 i = i + 2 @TO@ if a ][i + 1 == a ][i d = d + 1 else f = f + 1 @AT@ 173 @LENGTH@ 74\n" +
|
||||
"------UPD if@@if a ][i + 1 == a ][i d = d + 1 else f = f + 1 i = i + 2 @TO@ if a ][i + 1 == a ][i d = d + 1 else f = f + 1 @AT@ 179 @LENGTH@ 58\n" +
|
||||
"---------UPD else@@else f = f + 1 i = i + 2 @TO@ else f = f + 1 @AT@ 218 @LENGTH@ 25\n" +
|
||||
"------------UPD block@@ f = f + 1 i = i + 2 @TO@ f = f + 1 @AT@ 218 @LENGTH@ 26\n" +
|
||||
"---UPD block@@if a ][i + 1 == a ][i d = d + 1 else f = f + 1 i = i + 2 @TO@ if a ][i + 1 == a ][i d = d + 1 else f = f + 1 @AT@ 173 @LENGTH@ 56\n" +
|
||||
"------UPD if@@if a ][i + 1 == a ][i d = d + 1 else f = f + 1 i = i + 2 @TO@ if a ][i + 1 == a ][i d = d + 1 else f = f + 1 @AT@ 179 @LENGTH@ 56\n" +
|
||||
"---------UPD else@@else f = f + 1 i = i + 2 @TO@ else f = f + 1 @AT@ 218 @LENGTH@ 24\n" +
|
||||
"------------UPD block@@f = f + 1 i = i + 2 @TO@ f = f + 1 @AT@ 218 @LENGTH@ 19\n" +
|
||||
"---------------DEL expr_stmt@@i = i + 2 @AT@ 233 @LENGTH@ 9\n" +
|
||||
"------------------DEL expr@@i = i + 2 @AT@ 233 @LENGTH@ 9\n" +
|
||||
"---------------------DEL name@@i @AT@ 233 @LENGTH@ 1\n" +
|
||||
@@ -352,24 +353,24 @@ public class TestRealCases {
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("452-B-7271987-7272004.c");
|
||||
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD block@@ int i j n m x i_temp 1 scanf \"%d %d\" & n & m if n == 0 printf \"0 1\\n\" printf \"0 %d\\n\" m printf \"0 0\\n\" printf \"0 %d\\n\" ( m - 1 ) 0 elseif if m == 0 printf \"1 0\\n\" printf \"%d 0\\n\" n printf \"0 0\\n\" printf \"%d 0\\n\" ( n - 1 ) 0 elseif if ( m == n ) && ( n == 1 ) printf \"%d %d\\n\" n m printf \"0 0\\n\" printf \"%d 0\\n\" n printf \"0 %d\\n\" ( m ) 0 elseif if m == n if m + m * 1.41f > ( 2 * sqrt double m * m + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m printf \"0 0\\n\" printf \"%d 0\\n\" n printf \"0 %d\\n\" n else printf \"%d %d\\n\" n - 1 m printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"1 0\\n\" 0 elseif if n < m if m + sqrt ( double ) n * n + m * m < ( 2 * sqrt double n - 1 * ( n - 1 ) + ( m ) * ( m ) ) printf \"%d %d\\n\" n - 1 m printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"1 0\\n\" 0 else printf \"%d %d\\n0 0 \\n0 %d\\n%d 0\\n\" n m m n 0 elseif if n > m if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" 0 else printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m 0 @TO@ int i j n m x i_temp 1 scanf \"%d %d\" & n & m if n == 0 printf \"0 1\\n\" printf \"0 %d\\n\" m printf \"0 0\\n\" printf \"0 %d\\n\" ( m - 1 ) 0 elseif if m == 0 printf \"1 0\\n\" printf \"%d 0\\n\" n printf \"0 0\\n\" printf \"%d 0\\n\" ( n - 1 ) 0 elseif if ( m == n ) && ( n == 1 ) printf \"%d %d\\n\" n m printf \"0 0\\n\" printf \"%d 0\\n\" n printf \"0 %d\\n\" ( m ) 0 elseif if m == n if m + m * 1.41f > ( 2 * sqrt double m * m + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m printf \"0 0\\n\" printf \"%d 0\\n\" n printf \"0 %d\\n\" n else printf \"%d %d\\n\" n - 1 m printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"1 0\\n\" 0 elseif if n < m if m + sqrt ( double ) n * n + m * m < ( 2 * sqrt double n - 1 * ( n - 1 ) + ( m ) * ( m ) ) printf \"%d %d\\n\" n - 1 m printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"1 0\\n\" 0 else printf \"%d %d\\n0 0 \\n0 %d\\n%d 0\\n\" n m m n 0 elseif if n > m if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" 0 else printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m 0 0 @AT@ 115 @LENGTH@ 1270\n" +
|
||||
"---UPD if@@if n == 0 printf \"0 1\\n\" printf \"0 %d\\n\" m printf \"0 0\\n\" printf \"0 %d\\n\" ( m - 1 ) 0 elseif if m == 0 printf \"1 0\\n\" printf \"%d 0\\n\" n printf \"0 0\\n\" printf \"%d 0\\n\" ( n - 1 ) 0 elseif if ( m == n ) && ( n == 1 ) printf \"%d %d\\n\" n m printf \"0 0\\n\" printf \"%d 0\\n\" n printf \"0 %d\\n\" ( m ) 0 elseif if m == n if m + m * 1.41f > ( 2 * sqrt double m * m + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m printf \"0 0\\n\" printf \"%d 0\\n\" n printf \"0 %d\\n\" n else printf \"%d %d\\n\" n - 1 m printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"1 0\\n\" 0 elseif if n < m if m + sqrt ( double ) n * n + m * m < ( 2 * sqrt double n - 1 * ( n - 1 ) + ( m ) * ( m ) ) printf \"%d %d\\n\" n - 1 m printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"1 0\\n\" 0 else printf \"%d %d\\n0 0 \\n0 %d\\n%d 0\\n\" n m m n 0 elseif if n > m if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" 0 else printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m 0 @TO@ if n == 0 printf \"0 1\\n\" printf \"0 %d\\n\" m printf \"0 0\\n\" printf \"0 %d\\n\" ( m - 1 ) 0 elseif if m == 0 printf \"1 0\\n\" printf \"%d 0\\n\" n printf \"0 0\\n\" printf \"%d 0\\n\" ( n - 1 ) 0 elseif if ( m == n ) && ( n == 1 ) printf \"%d %d\\n\" n m printf \"0 0\\n\" printf \"%d 0\\n\" n printf \"0 %d\\n\" ( m ) 0 elseif if m == n if m + m * 1.41f > ( 2 * sqrt double m * m + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m printf \"0 0\\n\" printf \"%d 0\\n\" n printf \"0 %d\\n\" n else printf \"%d %d\\n\" n - 1 m printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"1 0\\n\" 0 elseif if n < m if m + sqrt ( double ) n * n + m * m < ( 2 * sqrt double n - 1 * ( n - 1 ) + ( m ) * ( m ) ) printf \"%d %d\\n\" n - 1 m printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"1 0\\n\" 0 else printf \"%d %d\\n0 0 \\n0 %d\\n%d 0\\n\" n m m n 0 elseif if n > m if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" 0 else printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m 0 @AT@ 168 @LENGTH@ 1062\n" +
|
||||
"------UPD elseif@@elseif if n > m if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" 0 else printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m 0 @TO@ elseif if n > m if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" 0 else printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m 0 @AT@ 1116 @LENGTH@ 247\n" +
|
||||
"---------UPD if@@if n > m if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" 0 else printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m 0 @TO@ if n > m if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" 0 else printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m 0 @AT@ 1116 @LENGTH@ 240\n" +
|
||||
"------------UPD then@@ if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" 0 else printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m 0 @TO@ if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" 0 else printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m 0 @AT@ 1123 @LENGTH@ 231\n" +
|
||||
"---------------UPD block@@ if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" 0 else printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m 0 @TO@ if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" 0 else printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m 0 @AT@ 1123 @LENGTH@ 260\n" +
|
||||
"------------------UPD if@@if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" 0 else printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m 0 @TO@ if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" 0 else printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m 0 @AT@ 1129 @LENGTH@ 230\n" +
|
||||
"---------------------UPD else@@else printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m 0 @TO@ else printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m 0 @AT@ 1313 @LENGTH@ 51\n" +
|
||||
"------------------------UPD block@@ printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m 0 @TO@ printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m 0 @AT@ 1313 @LENGTH@ 66\n" +
|
||||
"---------------------------UPD expr_stmt@@printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m @TO@ printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m @AT@ 1318 @LENGTH@ 42\n" +
|
||||
"------------------------------UPD expr@@printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m @TO@ printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m @AT@ 1318 @LENGTH@ 42\n" +
|
||||
"---------------------------------UPD call@@printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m @TO@ printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m @AT@ 1318 @LENGTH@ 42\n" +
|
||||
"------------------------------------UPD argument_list@@ \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m @TO@ \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m @AT@ 1324 @LENGTH@ 37\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD block@@int i j n m x i_temp 1 scanf \"%d %d\" & n & m if n == 0 printf \"0 1\\n\" printf \"0 %d\\n\" m printf \"0 0\\n\" printf \"0 %d\\n\" ( m - 1 ) return 0 elseif if m == 0 printf \"1 0\\n\" printf \"%d 0\\n\" n printf \"0 0\\n\" printf \"%d 0\\n\" ( n - 1 ) return 0 elseif if ( m == n ) && ( n == 1 ) printf \"%d %d\\n\" n m printf \"0 0\\n\" printf \"%d 0\\n\" n printf \"0 %d\\n\" ( m ) return 0 elseif if m == n if m + m * 1.41f > ( 2 * sqrt double m * m + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m printf \"0 0\\n\" printf \"%d 0\\n\" n printf \"0 %d\\n\" n else printf \"%d %d\\n\" n - 1 m printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"1 0\\n\" return 0 elseif if n < m if m + sqrt ( double ) n * n + m * m < ( 2 * sqrt double n - 1 * ( n - 1 ) + ( m ) * ( m ) ) printf \"%d %d\\n\" n - 1 m printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"1 0\\n\" return 0 else printf \"%d %d\\n0 0 \\n0 %d\\n%d 0\\n\" n m m n return 0 elseif if n > m if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" return 0 else printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m return 0 @TO@ int i j n m x i_temp 1 scanf \"%d %d\" & n & m if n == 0 printf \"0 1\\n\" printf \"0 %d\\n\" m printf \"0 0\\n\" printf \"0 %d\\n\" ( m - 1 ) return 0 elseif if m == 0 printf \"1 0\\n\" printf \"%d 0\\n\" n printf \"0 0\\n\" printf \"%d 0\\n\" ( n - 1 ) return 0 elseif if ( m == n ) && ( n == 1 ) printf \"%d %d\\n\" n m printf \"0 0\\n\" printf \"%d 0\\n\" n printf \"0 %d\\n\" ( m ) return 0 elseif if m == n if m + m * 1.41f > ( 2 * sqrt double m * m + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m printf \"0 0\\n\" printf \"%d 0\\n\" n printf \"0 %d\\n\" n else printf \"%d %d\\n\" n - 1 m printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"1 0\\n\" return 0 elseif if n < m if m + sqrt ( double ) n * n + m * m < ( 2 * sqrt double n - 1 * ( n - 1 ) + ( m ) * ( m ) ) printf \"%d %d\\n\" n - 1 m printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"1 0\\n\" return 0 else printf \"%d %d\\n0 0 \\n0 %d\\n%d 0\\n\" n m m n return 0 elseif if n > m if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" return 0 else printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m return 0 return 0 @AT@ 115 @LENGTH@ 1106\n" +
|
||||
"---UPD if@@if n == 0 printf \"0 1\\n\" printf \"0 %d\\n\" m printf \"0 0\\n\" printf \"0 %d\\n\" ( m - 1 ) return 0 elseif if m == 0 printf \"1 0\\n\" printf \"%d 0\\n\" n printf \"0 0\\n\" printf \"%d 0\\n\" ( n - 1 ) return 0 elseif if ( m == n ) && ( n == 1 ) printf \"%d %d\\n\" n m printf \"0 0\\n\" printf \"%d 0\\n\" n printf \"0 %d\\n\" ( m ) return 0 elseif if m == n if m + m * 1.41f > ( 2 * sqrt double m * m + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m printf \"0 0\\n\" printf \"%d 0\\n\" n printf \"0 %d\\n\" n else printf \"%d %d\\n\" n - 1 m printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"1 0\\n\" return 0 elseif if n < m if m + sqrt ( double ) n * n + m * m < ( 2 * sqrt double n - 1 * ( n - 1 ) + ( m ) * ( m ) ) printf \"%d %d\\n\" n - 1 m printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"1 0\\n\" return 0 else printf \"%d %d\\n0 0 \\n0 %d\\n%d 0\\n\" n m m n return 0 elseif if n > m if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" return 0 else printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m return 0 @TO@ if n == 0 printf \"0 1\\n\" printf \"0 %d\\n\" m printf \"0 0\\n\" printf \"0 %d\\n\" ( m - 1 ) return 0 elseif if m == 0 printf \"1 0\\n\" printf \"%d 0\\n\" n printf \"0 0\\n\" printf \"%d 0\\n\" ( n - 1 ) return 0 elseif if ( m == n ) && ( n == 1 ) printf \"%d %d\\n\" n m printf \"0 0\\n\" printf \"%d 0\\n\" n printf \"0 %d\\n\" ( m ) return 0 elseif if m == n if m + m * 1.41f > ( 2 * sqrt double m * m + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m printf \"0 0\\n\" printf \"%d 0\\n\" n printf \"0 %d\\n\" n else printf \"%d %d\\n\" n - 1 m printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"1 0\\n\" return 0 elseif if n < m if m + sqrt ( double ) n * n + m * m < ( 2 * sqrt double n - 1 * ( n - 1 ) + ( m ) * ( m ) ) printf \"%d %d\\n\" n - 1 m printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"1 0\\n\" return 0 else printf \"%d %d\\n0 0 \\n0 %d\\n%d 0\\n\" n m m n return 0 elseif if n > m if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" return 0 else printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m return 0 @AT@ 168 @LENGTH@ 1061\n" +
|
||||
"------UPD elseif@@elseif if n > m if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" return 0 else printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m return 0 @TO@ elseif if n > m if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" return 0 else printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m return 0 @AT@ 1116 @LENGTH@ 249\n" +
|
||||
"---------UPD if@@if n > m if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" return 0 else printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m return 0 @TO@ if n > m if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" return 0 else printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m return 0 @AT@ 1116 @LENGTH@ 242\n" +
|
||||
"------------UPD then@@if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" return 0 else printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m return 0 @TO@ if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" return 0 else printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m return 0 @AT@ 1123 @LENGTH@ 233\n" +
|
||||
"---------------UPD block@@if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" return 0 else printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m return 0 @TO@ if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" return 0 else printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m return 0 @AT@ 1123 @LENGTH@ 233\n" +
|
||||
"------------------UPD if@@if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" return 0 else printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m return 0 @TO@ if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" return 0 else printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m return 0 @AT@ 1129 @LENGTH@ 233\n" +
|
||||
"---------------------UPD else@@else printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m return 0 @TO@ else printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m return 0 @AT@ 1313 @LENGTH@ 55\n" +
|
||||
"------------------------UPD block@@printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m return 0 @TO@ printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m return 0 @AT@ 1313 @LENGTH@ 50\n" +
|
||||
"---------------------------UPD expr_stmt@@printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m @TO@ printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m @AT@ 1318 @LENGTH@ 41\n" +
|
||||
"------------------------------UPD expr@@printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m @TO@ printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m @AT@ 1318 @LENGTH@ 41\n" +
|
||||
"---------------------------------UPD call@@printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m @TO@ printf \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m @AT@ 1318 @LENGTH@ 41\n" +
|
||||
"------------------------------------UPD argument_list@@\"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m @TO@ \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" n m n m @AT@ 1324 @LENGTH@ 34\n" +
|
||||
"---------------------------------------UPD argument@@\"%d %d\\n0 0 \\n%d \\n0 %d\\n\" @TO@ \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" @AT@ 1325 @LENGTH@ 26\n" +
|
||||
"------------------------------------------UPD expr@@\"%d %d\\n0 0 \\n%d \\n0 %d\\n\" @TO@ \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" @AT@ 1325 @LENGTH@ 26\n" +
|
||||
"---------------------------------------------UPD literal@@\"%d %d\\n0 0 \\n%d \\n0 %d\\n\" @TO@ \"%d %d\\n0 0 \\n%d 0\\n0 %d\\n\" @AT@ 1325 @LENGTH@ 26\n" +
|
||||
"---INS return@@ 0 @TO@ block@@ int i j n m x i_temp 1 scanf \"%d %d\" & n & m if n == 0 printf \"0 1\\n\" printf \"0 %d\\n\" m printf \"0 0\\n\" printf \"0 %d\\n\" ( m - 1 ) 0 elseif if m == 0 printf \"1 0\\n\" printf \"%d 0\\n\" n printf \"0 0\\n\" printf \"%d 0\\n\" ( n - 1 ) 0 elseif if ( m == n ) && ( n == 1 ) printf \"%d %d\\n\" n m printf \"0 0\\n\" printf \"%d 0\\n\" n printf \"0 %d\\n\" ( m ) 0 elseif if m == n if m + m * 1.41f > ( 2 * sqrt double m * m + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m printf \"0 0\\n\" printf \"%d 0\\n\" n printf \"0 %d\\n\" n else printf \"%d %d\\n\" n - 1 m printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"1 0\\n\" 0 elseif if n < m if m + sqrt ( double ) n * n + m * m < ( 2 * sqrt double n - 1 * ( n - 1 ) + ( m ) * ( m ) ) printf \"%d %d\\n\" n - 1 m printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"1 0\\n\" 0 else printf \"%d %d\\n0 0 \\n0 %d\\n%d 0\\n\" n m m n 0 elseif if n > m if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" 0 else printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m 0 @AT@ 1385 @LENGTH@ 10\n" +
|
||||
"------INS expr@@0 @TO@ return@@ 0 @AT@ 1392 @LENGTH@ 1\n" +
|
||||
"---INS return@@return 0 @TO@ block@@int i j n m x i_temp 1 scanf \"%d %d\" & n & m if n == 0 printf \"0 1\\n\" printf \"0 %d\\n\" m printf \"0 0\\n\" printf \"0 %d\\n\" ( m - 1 ) return 0 elseif if m == 0 printf \"1 0\\n\" printf \"%d 0\\n\" n printf \"0 0\\n\" printf \"%d 0\\n\" ( n - 1 ) return 0 elseif if ( m == n ) && ( n == 1 ) printf \"%d %d\\n\" n m printf \"0 0\\n\" printf \"%d 0\\n\" n printf \"0 %d\\n\" ( m ) return 0 elseif if m == n if m + m * 1.41f > ( 2 * sqrt double m * m + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m printf \"0 0\\n\" printf \"%d 0\\n\" n printf \"0 %d\\n\" n else printf \"%d %d\\n\" n - 1 m printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"1 0\\n\" return 0 elseif if n < m if m + sqrt ( double ) n * n + m * m < ( 2 * sqrt double n - 1 * ( n - 1 ) + ( m ) * ( m ) ) printf \"%d %d\\n\" n - 1 m printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"1 0\\n\" return 0 else printf \"%d %d\\n0 0 \\n0 %d\\n%d 0\\n\" n m m n return 0 elseif if n > m if n + sqrt ( double ) n * n + m * m < ( 2 * sqrt ( double ) n * n + ( m - 1 ) * ( m - 1 ) ) printf \"%d %d\\n\" n m - 1 printf \"0 0\\n\" printf \"%d %d\\n\" n m printf \"0 1\\n\" return 0 else printf \"%d %d\\n0 0 \\n%d \\n0 %d\\n\" n m n m return 0 @AT@ 1385 @LENGTH@ 8\n" +
|
||||
"------INS expr@@0 @TO@ return@@return 0 @AT@ 1392 @LENGTH@ 1\n" +
|
||||
"---------INS literal@@0 @TO@ expr@@0 @AT@ 1392 @LENGTH@ 1\n");
|
||||
|
||||
|
||||
@@ -380,10 +381,10 @@ public class TestRealCases {
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("158-E-1314159-1314160.c");
|
||||
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD expr_stmt@@ans = max ans 86401 - dp ][k @TO@ ans = max ans 86400 - dp ][k @AT@ 377 @LENGTH@ 29\n" +
|
||||
"---UPD expr@@ans = max ans 86401 - dp ][k @TO@ ans = max ans 86400 - dp ][k @AT@ 377 @LENGTH@ 29\n" +
|
||||
"------UPD call@@max ans 86401 - dp ][k @TO@ max ans 86400 - dp ][k @AT@ 383 @LENGTH@ 23\n" +
|
||||
"---------UPD argument_list@@ ans 86401 - dp ][k @TO@ ans 86400 - dp ][k @AT@ 386 @LENGTH@ 23\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD expr_stmt@@ans = max ans 86401 - dp ][k @TO@ ans = max ans 86400 - dp ][k @AT@ 377 @LENGTH@ 28\n" +
|
||||
"---UPD expr@@ans = max ans 86401 - dp ][k @TO@ ans = max ans 86400 - dp ][k @AT@ 377 @LENGTH@ 28\n" +
|
||||
"------UPD call@@max ans 86401 - dp ][k @TO@ max ans 86400 - dp ][k @AT@ 383 @LENGTH@ 22\n" +
|
||||
"---------UPD argument_list@@ans 86401 - dp ][k @TO@ ans 86400 - dp ][k @AT@ 386 @LENGTH@ 18\n" +
|
||||
"------------UPD argument@@86401 - dp ][k @TO@ 86400 - dp ][k @AT@ 393 @LENGTH@ 14\n" +
|
||||
"---------------UPD expr@@86401 - dp ][k @TO@ 86400 - dp ][k @AT@ 393 @LENGTH@ 14\n" +
|
||||
"------------------UPD literal@@86401 @TO@ 86400 @AT@ 393 @LENGTH@ 5\n");
|
||||
@@ -395,10 +396,10 @@ public class TestRealCases {
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("250-A-2762401-2762408.c");
|
||||
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD expr_stmt@@folders = ceil negative / 2 @TO@ folders = ceil negative / 2.0 @AT@ 289 @LENGTH@ 28\n" +
|
||||
"---UPD expr@@folders = ceil negative / 2 @TO@ folders = ceil negative / 2.0 @AT@ 289 @LENGTH@ 28\n" +
|
||||
"------UPD call@@ceil negative / 2 @TO@ ceil negative / 2.0 @AT@ 299 @LENGTH@ 18\n" +
|
||||
"---------UPD argument_list@@ negative / 2 @TO@ negative / 2.0 @AT@ 303 @LENGTH@ 13\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD expr_stmt@@folders = ceil negative / 2 @TO@ folders = ceil negative / 2.0 @AT@ 289 @LENGTH@ 27\n" +
|
||||
"---UPD expr@@folders = ceil negative / 2 @TO@ folders = ceil negative / 2.0 @AT@ 289 @LENGTH@ 27\n" +
|
||||
"------UPD call@@ceil negative / 2 @TO@ ceil negative / 2.0 @AT@ 299 @LENGTH@ 17\n" +
|
||||
"---------UPD argument_list@@negative / 2 @TO@ negative / 2.0 @AT@ 303 @LENGTH@ 12\n" +
|
||||
"------------UPD argument@@negative / 2 @TO@ negative / 2.0 @AT@ 304 @LENGTH@ 12\n" +
|
||||
"---------------UPD expr@@negative / 2 @TO@ negative / 2.0 @AT@ 304 @LENGTH@ 12\n" +
|
||||
"------------------UPD literal@@2 @TO@ 2.0 @AT@ 313 @LENGTH@ 1\n");
|
||||
@@ -410,10 +411,10 @@ public class TestRealCases {
|
||||
//TODO
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("31-B-6435804-6435825.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD for@@for i = 1 i <= strlen s i ++ if n == - 1 if s ][i != '@' n = i else printf \"No solution\\n\" ( 0 ) if fl == 1 if s ][i != '@' fl = 0 if flag != 0 jj ++ cc ][jj = ',' for j = n j <= i j ++ jj ++ cc ][jj = s ][j else for j = n j <= i j ++ jj ++ cc ][jj = s ][j flag = 1 n = - 1 kon = i exit = 1 else printf \"No solution\\n\" ( 0 ) elseif if s ][i == '@' fl = 1 @TO@ for i = 1 i < strlen s i ++ if n == - 1 if s ][i != '@' n = i else printf \"No solution\\n\" ( 0 ) if fl == 1 if s ][i != '@' fl = 0 if flag != 0 jj ++ cc ][jj = ',' for j = n j <= i j ++ jj ++ cc ][jj = s ][j else for j = n j <= i j ++ jj ++ cc ][jj = s ][j flag = 1 n = - 1 kon = i exit = 1 else printf \"No solution\\n\" ( 0 ) elseif if s ][i == '@' fl = 1 @AT@ 225 @LENGTH@ 369\n" +
|
||||
"---UPD control@@ i = 1 i <= strlen s i ++ @TO@ i = 1 i < strlen s i ++ @AT@ 225 @LENGTH@ 29\n" +
|
||||
"------UPD condition@@i <= strlen s @TO@ i < strlen s @AT@ 233 @LENGTH@ 14\n" +
|
||||
"---------UPD expr@@i <= strlen s @TO@ i < strlen s @AT@ 233 @LENGTH@ 14\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD for@@for i = 1 i <= strlen s i ++ if n == - 1 if s ][i != '@' n = i else printf \"No solution\\n\" return ( 0 ) if fl == 1 if s ][i != '@' fl = 0 if flag != 0 jj ++ cc ][jj = ',' for j = n j <= i j ++ jj ++ cc ][jj = s ][j else for j = n j <= i j ++ jj ++ cc ][jj = s ][j flag = 1 n = - 1 kon = i exit = 1 else printf \"No solution\\n\" return ( 0 ) elseif if s ][i == '@' fl = 1 @TO@ for i = 1 i < strlen s i ++ if n == - 1 if s ][i != '@' n = i else printf \"No solution\\n\" return ( 0 ) if fl == 1 if s ][i != '@' fl = 0 if flag != 0 jj ++ cc ][jj = ',' for j = n j <= i j ++ jj ++ cc ][jj = s ][j else for j = n j <= i j ++ jj ++ cc ][jj = s ][j flag = 1 n = - 1 kon = i exit = 1 else printf \"No solution\\n\" return ( 0 ) elseif if s ][i == '@' fl = 1 @AT@ 225 @LENGTH@ 368\n" +
|
||||
"---UPD control@@i = 1 i <= strlen s i ++ @TO@ i = 1 i < strlen s i ++ @AT@ 225 @LENGTH@ 24\n" +
|
||||
"------UPD condition@@i <= strlen s @TO@ i < strlen s @AT@ 233 @LENGTH@ 13\n" +
|
||||
"---------UPD expr@@i <= strlen s @TO@ i < strlen s @AT@ 233 @LENGTH@ 13\n" +
|
||||
"------------UPD operator@@<= @TO@ < @AT@ 235 @LENGTH@ 2\n");
|
||||
|
||||
}
|
||||
@@ -423,8 +424,8 @@ public class TestRealCases {
|
||||
//TODO
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("644-A-18166947-18166954.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD for@@for i = 0 i < b i ++ for j = 0 j < b j ++ printf \"%lld \" array ][i ][j printf \"\\n\" @TO@ for i = 0 i < a i ++ for j = 0 j < b j ++ printf \"%lld \" array ][i ][j printf \"\\n\" @AT@ 1251 @LENGTH@ 86\n" +
|
||||
"---UPD control@@ i = 0 i < b i ++ @TO@ i = 0 i < a i ++ @AT@ 1251 @LENGTH@ 14\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD for@@for i = 0 i < b i ++ for j = 0 j < b j ++ printf \"%lld \" array ][i ][j printf \"\\n\" @TO@ for i = 0 i < a i ++ for j = 0 j < b j ++ printf \"%lld \" array ][i ][j printf \"\\n\" @AT@ 1251 @LENGTH@ 82\n" +
|
||||
"---UPD control@@i = 0 i < b i ++ @TO@ i = 0 i < a i ++ @AT@ 1251 @LENGTH@ 16\n" +
|
||||
"------UPD condition@@i < b @TO@ i < a @AT@ 1256 @LENGTH@ 5\n" +
|
||||
"---------UPD expr@@i < b @TO@ i < a @AT@ 1256 @LENGTH@ 5\n" +
|
||||
"------------UPD name@@b @TO@ a @AT@ 1258 @LENGTH@ 1\n");
|
||||
@@ -435,8 +436,8 @@ public class TestRealCases {
|
||||
public void test_5_B_10350073_10350082() throws IOException {
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("5-B-10350073-10350082.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD if@@if ! ( ( ml - l ) % 2 ) if right sl += 1 right = 1 - right @TO@ if ( ml - l ) % 2 if right sl += 1 right = 1 - right @AT@ 515 @LENGTH@ 59\n" +
|
||||
"---UPD condition@@ ! ( ( ml - l ) % 2 ) @TO@ ( ml - l ) % 2 @AT@ 515 @LENGTH@ 18\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD if@@if ! ( ( ml - l ) % 2 ) if right sl += 1 right = 1 - right @TO@ if ( ml - l ) % 2 if right sl += 1 right = 1 - right @AT@ 515 @LENGTH@ 58\n" +
|
||||
"---UPD condition@@! ( ( ml - l ) % 2 ) @TO@ ( ml - l ) % 2 @AT@ 515 @LENGTH@ 20\n" +
|
||||
"------UPD expr@@! ( ( ml - l ) % 2 ) @TO@ ( ml - l ) % 2 @AT@ 516 @LENGTH@ 20\n" +
|
||||
"---------DEL operator@@! @AT@ 516 @LENGTH@ 1\n" +
|
||||
"---------DEL operator@@( @AT@ 518 @LENGTH@ 1\n" +
|
||||
@@ -448,7 +449,7 @@ public class TestRealCases {
|
||||
public void test_675_A_18211752_18211767() throws IOException {
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("675-A-18211752-18211767.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"MOV return@@ 0 @TO@ block@@ if a == b printf \"YES\" else printf \"NO\" @AT@ 242 @LENGTH@ 10\n");
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"MOV return@@return 0 @TO@ block@@if a == b printf \"YES\" else printf \"NO\" @AT@ 242 @LENGTH@ 8\n");
|
||||
|
||||
}
|
||||
|
||||
@@ -457,8 +458,8 @@ public class TestRealCases {
|
||||
//TODO
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("158-A-18278572-18278586.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD while@@while a ][i >= a ][k && i <= n count ++ i ++ @TO@ while a ][i >= a ][k && i <= n && a ][i != 0 count ++ i ++ @AT@ 501 @LENGTH@ 45\n" +
|
||||
"---UPD condition@@ a ][i >= a ][k && i <= n @TO@ a ][i >= a ][k && i <= n && a ][i != 0 @AT@ 501 @LENGTH@ 19\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD while@@while a ][i >= a ][k && i <= n count ++ i ++ @TO@ while a ][i >= a ][k && i <= n && a ][i != 0 count ++ i ++ @AT@ 501 @LENGTH@ 44\n" +
|
||||
"---UPD condition@@a ][i >= a ][k && i <= n @TO@ a ][i >= a ][k && i <= n && a ][i != 0 @AT@ 501 @LENGTH@ 24\n" +
|
||||
"------UPD expr@@a ][i >= a ][k && i <= n @TO@ a ][i >= a ][k && i <= n && a ][i != 0 @AT@ 502 @LENGTH@ 24\n" +
|
||||
"---------INS operator@@&& @TO@ expr@@a ][i >= a ][k && i <= n @AT@ 518 @LENGTH@ 2\n" +
|
||||
"---------INS name@@a ][i @TO@ expr@@a ][i >= a ][k && i <= n @AT@ 520 @LENGTH@ 5\n" +
|
||||
@@ -476,7 +477,7 @@ public class TestRealCases {
|
||||
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("31-B-136044-136045.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"MOV if@@if flag puts ans + 1 else printf \"No solution\\n\" @TO@ block@@ long i l flag 0 tot 0 gets str + 1 l = strlen str + 1 if str ][1 == '@' || str ][l == '@' end for i = 1 i <= l - 2 i ++ if str ][i == '@' && ( str ][i + 1 == '@' || str ][i + 2 == '@' ) end for i = 1 i <= l i ++ if flag && str ][i + 1 == '@' ans ][++ tot = ',' if str ][i == '@' flag = 1 ans ][++ tot = str ][i if flag puts ans + 1 else printf \"No solution\\n\" end 0 @AT@ 937 @LENGTH@ 50\n");
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"MOV if@@if flag puts ans + 1 else printf \"No solution\\n\" @TO@ block@@long i l flag 0 tot 0 gets str + 1 l = strlen str + 1 if str ][1 == '@' || str ][l == '@' end for i = 1 i <= l - 2 i ++ if str ][i == '@' && ( str ][i + 1 == '@' || str ][i + 2 == '@' ) end for i = 1 i <= l i ++ if flag && str ][i + 1 == '@' ans ][++ tot = ',' if str ][i == '@' flag = 1 ans ][++ tot = str ][i if flag puts ans + 1 else printf \"No solution\\n\" end return 0 @AT@ 937 @LENGTH@ 48\n");
|
||||
|
||||
}
|
||||
|
||||
@@ -485,7 +486,7 @@ public class TestRealCases {
|
||||
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("432-A-16886797-16886828.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"MOV if@@if z <= 5 - y s ++ @TO@ block@@scanf \"%d\" & z @AT@ 132 @LENGTH@ 18\n");
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"MOV if@@if z <= 5 - y s ++ @TO@ block@@scanf \"%d\" & z @AT@ 132 @LENGTH@ 18\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -493,9 +494,9 @@ public class TestRealCases {
|
||||
//TODO macro
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("507-A-16886367-16886377.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD block@@ int x 0 n 0 s 0 i j k h ][105 0 a ][105 0 c ][105 0 y 0 top 0 scanf \"%d %d\" & n & k FOR i 0 n scanf \"%d\" & c ][i FOR i 0 n a ][i = i + 1 FOR i 0 n FOR j 1 n if c ][j - 1 > c ][j s = c ][j c ][j = c ][j - 1 c ][j - 1 = s s = a ][j a ][j = a ][j - 1 a ][j - 1 = s FOR i 0 n top += c ][i if top > k break; printf \"%d\\n\" i FOR j 0 n printf \"%d \" a ][j 0 @TO@ int x 0 n 0 s 0 i j k h ][105 0 a ][105 0 c ][105 0 y 0 top 0 scanf \"%d %d\" & n & k FOR i 0 n scanf \"%d\" & c ][i FOR i 0 n a ][i = i + 1 FOR i 0 n FOR j 1 n if c ][j - 1 > c ][j s = c ][j c ][j = c ][j - 1 c ][j - 1 = s s = a ][j a ][j = a ][j - 1 a ][j - 1 = s FOR i 0 n top += c ][i if top > k break; printf \"%d\\n\" i FOR j 0 i printf \"%d \" a ][j 0 @AT@ 270 @LENGTH@ 491\n" +
|
||||
"---UPD macro@@FOR j 0 n @TO@ FOR j 0 i @AT@ 701 @LENGTH@ 10\n" +
|
||||
"------UPD argument_list@@ j 0 n @TO@ j 0 i @AT@ 704 @LENGTH@ 8\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD block@@int x 0 n 0 s 0 i j k h ][105 0 a ][105 0 c ][105 0 y 0 top 0 scanf \"%d %d\" & n & k FOR i 0 n scanf \"%d\" & c ][i FOR i 0 n a ][i = i + 1 FOR i 0 n FOR j 1 n if c ][j - 1 > c ][j s = c ][j c ][j = c ][j - 1 c ][j - 1 = s s = a ][j a ][j = a ][j - 1 a ][j - 1 = s FOR i 0 n top += c ][i if top > k break; printf \"%d\\n\" i FOR j 0 n printf \"%d \" a ][j return 0 @TO@ int x 0 n 0 s 0 i j k h ][105 0 a ][105 0 c ][105 0 y 0 top 0 scanf \"%d %d\" & n & k FOR i 0 n scanf \"%d\" & c ][i FOR i 0 n a ][i = i + 1 FOR i 0 n FOR j 1 n if c ][j - 1 > c ][j s = c ][j c ][j = c ][j - 1 c ][j - 1 = s s = a ][j a ][j = a ][j - 1 a ][j - 1 = s FOR i 0 n top += c ][i if top > k break; printf \"%d\\n\" i FOR j 0 i printf \"%d \" a ][j return 0 @AT@ 270 @LENGTH@ 356\n" +
|
||||
"---UPD macro@@FOR j 0 n @TO@ FOR j 0 i @AT@ 701 @LENGTH@ 9\n" +
|
||||
"------UPD argument_list@@j 0 n @TO@ j 0 i @AT@ 704 @LENGTH@ 5\n" +
|
||||
"---------UPD argument@@n @TO@ i @AT@ 709 @LENGTH@ 1\n");
|
||||
}
|
||||
|
||||
@@ -504,9 +505,9 @@ public class TestRealCases {
|
||||
//TODO macro
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("25-D-110126-110132.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD block@@ int i j k l m n int a ][1200 b ][1200 unused ][1200 int ind ][1200 int cnt ][1200 int res_a ][1200 res_b ][1200 res_c ][1200 res_d ][1200 int shima int res bef scanf \"%d\" & n m = n - 1 rep i m scanf \"%d%d\" a + i b + i , a ][i -- , b ][i -- unionInit ind n rep i m unionConnect ind a ][i b ][i shima = 0 rep i m cnt ][unionGet ind i = 1 rep i n shima += cnt ][i res = 0 bef = - 1 rep i n if cnt ][i if bef >= 0 res_c ][res = bef res_d ][res ++ = i bef = i res = 0 rep k m unused ][k = 0 rep k m unionInit ind n rep i m if unused ][i == 0 if i != k unionConnect ind a ][i b ][i rep i n cnt ][i = 0 rep i n cnt ][unionGet ind i = 1 j = 0 rep i n j += cnt ][i if j == shima unused ][k = 1 res_a ][res = a ][k res_b ][res ++ = b ][k printf \"%d\\n\" res rep i res printf \"%d %d %d %d\\n\" res_a ][i + 1 res_b ][i + 1 res_c ][i + 1 res_d ][i + 1 0 @TO@ int i j k l m n int a ][1200 b ][1200 unused ][1200 int ind ][1200 int cnt ][1200 int res_a ][1200 res_b ][1200 res_c ][1200 res_d ][1200 int shima int res bef scanf \"%d\" & n m = n - 1 rep i m scanf \"%d%d\" a + i b + i , a ][i -- , b ][i -- unionInit ind n rep i m unionConnect ind a ][i b ][i shima = 0 rep i n cnt ][unionGet ind i = 1 rep i n shima += cnt ][i res = 0 bef = - 1 rep i n if cnt ][i if bef >= 0 res_c ][res = bef res_d ][res ++ = i bef = i res = 0 rep k m unused ][k = 0 rep k m unionInit ind n rep i m if unused ][i == 0 if i != k unionConnect ind a ][i b ][i rep i n cnt ][i = 0 rep i n cnt ][unionGet ind i = 1 j = 0 rep i n j += cnt ][i if j == shima unused ][k = 1 res_a ][res = a ][k res_b ][res ++ = b ][k printf \"%d\\n\" res rep i res printf \"%d %d %d %d\\n\" res_a ][i + 1 res_b ][i + 1 res_c ][i + 1 res_d ][i + 1 0 @AT@ 411 @LENGTH@ 955\n" +
|
||||
"---UPD macro@@rep i m @TO@ rep i n @AT@ 746 @LENGTH@ 8\n" +
|
||||
"------UPD argument_list@@ i m @TO@ i n @AT@ 749 @LENGTH@ 6\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD block@@int i j k l m n int a ][1200 b ][1200 unused ][1200 int ind ][1200 int cnt ][1200 int res_a ][1200 res_b ][1200 res_c ][1200 res_d ][1200 int shima int res bef scanf \"%d\" & n m = n - 1 rep i m scanf \"%d%d\" a + i b + i , a ][i -- , b ][i -- unionInit ind n rep i m unionConnect ind a ][i b ][i shima = 0 rep i m cnt ][unionGet ind i = 1 rep i n shima += cnt ][i res = 0 bef = - 1 rep i n if cnt ][i if bef >= 0 res_c ][res = bef res_d ][res ++ = i bef = i res = 0 rep k m unused ][k = 0 rep k m unionInit ind n rep i m if unused ][i == 0 if i != k unionConnect ind a ][i b ][i rep i n cnt ][i = 0 rep i n cnt ][unionGet ind i = 1 j = 0 rep i n j += cnt ][i if j == shima unused ][k = 1 res_a ][res = a ][k res_b ][res ++ = b ][k printf \"%d\\n\" res rep i res printf \"%d %d %d %d\\n\" res_a ][i + 1 res_b ][i + 1 res_c ][i + 1 res_d ][i + 1 return 0 @TO@ int i j k l m n int a ][1200 b ][1200 unused ][1200 int ind ][1200 int cnt ][1200 int res_a ][1200 res_b ][1200 res_c ][1200 res_d ][1200 int shima int res bef scanf \"%d\" & n m = n - 1 rep i m scanf \"%d%d\" a + i b + i , a ][i -- , b ][i -- unionInit ind n rep i m unionConnect ind a ][i b ][i shima = 0 rep i n cnt ][unionGet ind i = 1 rep i n shima += cnt ][i res = 0 bef = - 1 rep i n if cnt ][i if bef >= 0 res_c ][res = bef res_d ][res ++ = i bef = i res = 0 rep k m unused ][k = 0 rep k m unionInit ind n rep i m if unused ][i == 0 if i != k unionConnect ind a ][i b ][i rep i n cnt ][i = 0 rep i n cnt ][unionGet ind i = 1 j = 0 rep i n j += cnt ][i if j == shima unused ][k = 1 res_a ][res = a ][k res_b ][res ++ = b ][k printf \"%d\\n\" res rep i res printf \"%d %d %d %d\\n\" res_a ][i + 1 res_b ][i + 1 res_c ][i + 1 res_d ][i + 1 return 0 @AT@ 411 @LENGTH@ 843\n" +
|
||||
"---UPD macro@@rep i m @TO@ rep i n @AT@ 746 @LENGTH@ 7\n" +
|
||||
"------UPD argument_list@@i m @TO@ i n @AT@ 749 @LENGTH@ 3\n" +
|
||||
"---------UPD argument@@m @TO@ n @AT@ 752 @LENGTH@ 1\n");
|
||||
}
|
||||
|
||||
@@ -515,10 +516,10 @@ public class TestRealCases {
|
||||
//TODO
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("490-A-14580360-14580456.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(),1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD block@@ int n i j k l scanf \"%d\" & n int a ][5005 b ][5005 c ][5005 d ][5005 int w 0 x 0 y 0 for i = 1 , j = 1 , k = 1 , l = 1 i <= n i ++ scanf \"%d\" & a ][i if a ][i == 1 b ][j = i w ++ j ++ elseif if a ][i == 2 c ][k = i x ++ k ++ elseif if a ][i == 3 d ][l = i y ++ l ++ int min w if x < min min = x elseif if y < min min = y printf \"%d\\n\" min for i = 1 i <= min i ++ printf \"%d %d %d\\n\" b ][i c ][i d ][i 0 @TO@ int n i j k l scanf \"%d\" & n int a ][5005 b ][5005 c ][5005 d ][5005 int w 0 x 0 y 0 for i = 1 , j = 1 , k = 1 , l = 1 i <= n i ++ scanf \"%d\" & a ][i if a ][i == 1 b ][j = i w ++ j ++ elseif if a ][i == 2 c ][k = i x ++ k ++ elseif if a ][i == 3 d ][l = i y ++ l ++ int min w if x < min min = x if y < min min = y printf \"%d\\n\" min for i = 1 i <= min i ++ printf \"%d %d %d\\n\" b ][i c ][i d ][i 0 @AT@ 51 @LENGTH@ 642\n" +
|
||||
"---UPD if@@if x < min min = x elseif if y < min min = y @TO@ if x < min min = x @AT@ 507 @LENGTH@ 46\n" +
|
||||
"------DEL elseif@@elseif if y < min min = y @AT@ 548 @LENGTH@ 26\n" +
|
||||
"---MOV if@@if y < min min = y @TO@ block@@ int n i j k l scanf \"%d\" & n int a ][5005 b ][5005 c ][5005 d ][5005 int w 0 x 0 y 0 for i = 1 , j = 1 , k = 1 , l = 1 i <= n i ++ scanf \"%d\" & a ][i if a ][i == 1 b ][j = i w ++ j ++ elseif if a ][i == 2 c ][k = i x ++ k ++ elseif if a ][i == 3 d ][l = i y ++ l ++ int min w if x < min min = x elseif if y < min min = y printf \"%d\\n\" min for i = 1 i <= min i ++ printf \"%d %d %d\\n\" b ][i c ][i d ][i 0 @AT@ 548 @LENGTH@ 19\n");
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD block@@int n i j k l scanf \"%d\" & n int a ][5005 b ][5005 c ][5005 d ][5005 int w 0 x 0 y 0 for i = 1 , j = 1 , k = 1 , l = 1 i <= n i ++ scanf \"%d\" & a ][i if a ][i == 1 b ][j = i w ++ j ++ elseif if a ][i == 2 c ][k = i x ++ k ++ elseif if a ][i == 3 d ][l = i y ++ l ++ int min w if x < min min = x elseif if y < min min = y printf \"%d\\n\" min for i = 1 i <= min i ++ printf \"%d %d %d\\n\" b ][i c ][i d ][i return 0 @TO@ int n i j k l scanf \"%d\" & n int a ][5005 b ][5005 c ][5005 d ][5005 int w 0 x 0 y 0 for i = 1 , j = 1 , k = 1 , l = 1 i <= n i ++ scanf \"%d\" & a ][i if a ][i == 1 b ][j = i w ++ j ++ elseif if a ][i == 2 c ][k = i x ++ k ++ elseif if a ][i == 3 d ][l = i y ++ l ++ int min w if x < min min = x if y < min min = y printf \"%d\\n\" min for i = 1 i <= min i ++ printf \"%d %d %d\\n\" b ][i c ][i d ][i return 0 @AT@ 51 @LENGTH@ 409\n" +
|
||||
"---UPD if@@if x < min min = x elseif if y < min min = y @TO@ if x < min min = x @AT@ 507 @LENGTH@ 44\n" +
|
||||
"------DEL elseif@@elseif if y < min min = y @AT@ 548 @LENGTH@ 25\n" +
|
||||
"---MOV if@@if y < min min = y @TO@ block@@int n i j k l scanf \"%d\" & n int a ][5005 b ][5005 c ][5005 d ][5005 int w 0 x 0 y 0 for i = 1 , j = 1 , k = 1 , l = 1 i <= n i ++ scanf \"%d\" & a ][i if a ][i == 1 b ][j = i w ++ j ++ elseif if a ][i == 2 c ][k = i x ++ k ++ elseif if a ][i == 3 d ][l = i y ++ l ++ int min w if x < min min = x elseif if y < min min = y printf \"%d\\n\" min for i = 1 i <= min i ++ printf \"%d %d %d\\n\" b ][i c ][i d ][i return 0 @AT@ 548 @LENGTH@ 18\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -526,15 +527,15 @@ public class TestRealCases {
|
||||
//TODO
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("336-A-11394760-11394769.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(), 1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(), "UPD block@@ ll x y ll zero 0 scanf \"%lld%lld\" & x & y if x >= 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" zero x + y x + y zero if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y elseif if x >= 0 && y < 0 printf \"%lld %lld %lld %lld\\n\" zero - ( x - y ) x - y zero else printf \"%lld %lld %lld %lld\\n\" - ( - x - y ) zero zero - ( - x - y ) 0 @TO@ ll x y ll zero 0 scanf \"%lld%lld\" & x & y if x >= 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" zero x + y x + y zero elseif if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y elseif if x >= 0 && y < 0 printf \"%lld %lld %lld %lld\\n\" zero - ( x - y ) x - y zero else printf \"%lld %lld %lld %lld\\n\" - ( - x - y ) zero zero - ( - x - y ) 0 @AT@ 72 @LENGTH@ 493\n" +
|
||||
"---DEL if@@if x >= 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" zero x + y x + y zero @AT@ 146 @LENGTH@ 74\n" +
|
||||
"---UPD if@@if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y elseif if x >= 0 && y < 0 printf \"%lld %lld %lld %lld\\n\" zero - ( x - y ) x - y zero else printf \"%lld %lld %lld %lld\\n\" - ( - x - y ) zero zero - ( - x - y ) @TO@ if x >= 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" zero x + y x + y zero elseif if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y elseif if x >= 0 && y < 0 printf \"%lld %lld %lld %lld\\n\" zero - ( x - y ) x - y zero else printf \"%lld %lld %lld %lld\\n\" - ( - x - y ) zero zero - ( - x - y ) @AT@ 245 @LENGTH@ 246\n" +
|
||||
"------MOV condition@@ x >= 0 && y >= 0 @TO@ if@@if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y elseif if x >= 0 && y < 0 printf \"%lld %lld %lld %lld\\n\" zero - ( x - y ) x - y zero else printf \"%lld %lld %lld %lld\\n\" - ( - x - y ) zero zero - ( - x - y ) @AT@ 146 @LENGTH@ 13\n" +
|
||||
"------MOV then@@ printf \"%lld %lld %lld %lld\\n\" zero x + y x + y zero @TO@ if@@if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y elseif if x >= 0 && y < 0 printf \"%lld %lld %lld %lld\\n\" zero - ( x - y ) x - y zero else printf \"%lld %lld %lld %lld\\n\" - ( - x - y ) zero zero - ( - x - y ) @AT@ 165 @LENGTH@ 54\n" +
|
||||
"------INS elseif@@elseif if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y @TO@ if@@if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y elseif if x >= 0 && y < 0 printf \"%lld %lld %lld %lld\\n\" zero - ( x - y ) x - y zero else printf \"%lld %lld %lld %lld\\n\" - ( - x - y ) zero zero - ( - x - y ) @AT@ 250 @LENGTH@ 90\n" +
|
||||
"---------INS if@@if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y @TO@ elseif@@elseif if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y @AT@ 250 @LENGTH@ 83\n" +
|
||||
"------------MOV condition@@ x < 0 && y >= 0 @TO@ if@@if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y @AT@ 245 @LENGTH@ 12\n" +
|
||||
"------------MOV then@@ printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y @TO@ if@@if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y @AT@ 263 @LENGTH@ 64\n");
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(), "UPD block@@ll x y ll zero 0 scanf \"%lld%lld\" & x & y if x >= 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" zero x + y x + y zero if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y elseif if x >= 0 && y < 0 printf \"%lld %lld %lld %lld\\n\" zero - ( x - y ) x - y zero else printf \"%lld %lld %lld %lld\\n\" - ( - x - y ) zero zero - ( - x - y ) return 0 @TO@ ll x y ll zero 0 scanf \"%lld%lld\" & x & y if x >= 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" zero x + y x + y zero elseif if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y elseif if x >= 0 && y < 0 printf \"%lld %lld %lld %lld\\n\" zero - ( x - y ) x - y zero else printf \"%lld %lld %lld %lld\\n\" - ( - x - y ) zero zero - ( - x - y ) return 0 @AT@ 72 @LENGTH@ 364\n" +
|
||||
"---DEL if@@if x >= 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" zero x + y x + y zero @AT@ 146 @LENGTH@ 72\n" +
|
||||
"---UPD if@@if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y elseif if x >= 0 && y < 0 printf \"%lld %lld %lld %lld\\n\" zero - ( x - y ) x - y zero else printf \"%lld %lld %lld %lld\\n\" - ( - x - y ) zero zero - ( - x - y ) @TO@ if x >= 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" zero x + y x + y zero elseif if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y elseif if x >= 0 && y < 0 printf \"%lld %lld %lld %lld\\n\" zero - ( x - y ) x - y zero else printf \"%lld %lld %lld %lld\\n\" - ( - x - y ) zero zero - ( - x - y ) @AT@ 245 @LENGTH@ 240\n" +
|
||||
"------MOV condition@@x >= 0 && y >= 0 @TO@ if@@if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y elseif if x >= 0 && y < 0 printf \"%lld %lld %lld %lld\\n\" zero - ( x - y ) x - y zero else printf \"%lld %lld %lld %lld\\n\" - ( - x - y ) zero zero - ( - x - y ) @AT@ 146 @LENGTH@ 16\n" +
|
||||
"------MOV then@@printf \"%lld %lld %lld %lld\\n\" zero x + y x + y zero @TO@ if@@if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y elseif if x >= 0 && y < 0 printf \"%lld %lld %lld %lld\\n\" zero - ( x - y ) x - y zero else printf \"%lld %lld %lld %lld\\n\" - ( - x - y ) zero zero - ( - x - y ) @AT@ 165 @LENGTH@ 52\n" +
|
||||
"------INS elseif@@elseif if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y @TO@ if@@if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y elseif if x >= 0 && y < 0 printf \"%lld %lld %lld %lld\\n\" zero - ( x - y ) x - y zero else printf \"%lld %lld %lld %lld\\n\" - ( - x - y ) zero zero - ( - x - y ) @AT@ 250 @LENGTH@ 88\n" +
|
||||
"---------INS if@@if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y @TO@ elseif@@elseif if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y @AT@ 250 @LENGTH@ 81\n" +
|
||||
"------------MOV condition@@x < 0 && y >= 0 @TO@ if@@if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y @AT@ 245 @LENGTH@ 15\n" +
|
||||
"------------MOV then@@printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y @TO@ if@@if x < 0 && y >= 0 printf \"%lld %lld %lld %lld\\n\" - ( - x + y ) zero zero - x + y @AT@ 263 @LENGTH@ 62\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -544,7 +545,7 @@ public class TestRealCases {
|
||||
//TODO
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("10-A-1998522-1998523.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(), 1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(), "INS expr_stmt@@lr = r @TO@ block@@ scanf \"%d %d\" & l & r e += ( r - l ) * p1 if l - lr <= t1 e += ( l - lr ) * p1 else e += t1 * p1 if l - lr <= t1 + t2 e += ( l - lr - t1 ) * p2 else e += t2 * p2 + ( l - lr - t1 - t2 ) * p3 @AT@ 465 @LENGTH@ 6\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(), "INS expr_stmt@@lr = r @TO@ block@@scanf \"%d %d\" & l & r e += ( r - l ) * p1 if l - lr <= t1 e += ( l - lr ) * p1 else e += t1 * p1 if l - lr <= t1 + t2 e += ( l - lr - t1 ) * p2 else e += t2 * p2 + ( l - lr - t1 - t2 ) * p3 @AT@ 465 @LENGTH@ 6\n" +
|
||||
"---INS expr@@lr = r @TO@ expr_stmt@@lr = r @AT@ 465 @LENGTH@ 6\n" +
|
||||
"------INS name@@lr @TO@ expr@@lr = r @AT@ 465 @LENGTH@ 2\n" +
|
||||
"------INS operator@@= @TO@ expr@@lr = r @AT@ 468 @LENGTH@ 1\n" +
|
||||
@@ -555,8 +556,8 @@ public class TestRealCases {
|
||||
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("328-B-4080800-4080805.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(), 1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(), "DEL for@@for i = 0 i < 10 i ++ printf \"%d %d\\n\" num ][i tnum ][i @AT@ 453 @LENGTH@ 57\n" +
|
||||
"---DEL control@@ i = 0 i < 10 i ++ @AT@ 453 @LENGTH@ 15\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(), "DEL for@@for i = 0 i < 10 i ++ printf \"%d %d\\n\" num ][i tnum ][i @AT@ 453 @LENGTH@ 55\n" +
|
||||
"---DEL control@@i = 0 i < 10 i ++ @AT@ 453 @LENGTH@ 17\n" +
|
||||
"------DEL init@@i = 0 @AT@ 454 @LENGTH@ 5\n" +
|
||||
"---------DEL expr@@i = 0 @AT@ 454 @LENGTH@ 5\n" +
|
||||
"------------DEL name@@i @AT@ 454 @LENGTH@ 1\n" +
|
||||
@@ -571,12 +572,12 @@ public class TestRealCases {
|
||||
"---------DEL expr@@i ++ @AT@ 463 @LENGTH@ 4\n" +
|
||||
"------------DEL name@@i @AT@ 463 @LENGTH@ 1\n" +
|
||||
"------------DEL operator@@++ @AT@ 464 @LENGTH@ 2\n" +
|
||||
"---DEL block@@ printf \"%d %d\\n\" num ][i tnum ][i @AT@ 467 @LENGTH@ 50\n" +
|
||||
"------DEL expr_stmt@@printf \"%d %d\\n\" num ][i tnum ][i @AT@ 477 @LENGTH@ 34\n" +
|
||||
"---------DEL expr@@printf \"%d %d\\n\" num ][i tnum ][i @AT@ 477 @LENGTH@ 34\n" +
|
||||
"------------DEL call@@printf \"%d %d\\n\" num ][i tnum ][i @AT@ 477 @LENGTH@ 34\n" +
|
||||
"---DEL block@@printf \"%d %d\\n\" num ][i tnum ][i @AT@ 467 @LENGTH@ 33\n" +
|
||||
"------DEL expr_stmt@@printf \"%d %d\\n\" num ][i tnum ][i @AT@ 477 @LENGTH@ 33\n" +
|
||||
"---------DEL expr@@printf \"%d %d\\n\" num ][i tnum ][i @AT@ 477 @LENGTH@ 33\n" +
|
||||
"------------DEL call@@printf \"%d %d\\n\" num ][i tnum ][i @AT@ 477 @LENGTH@ 33\n" +
|
||||
"---------------DEL name@@printf @AT@ 477 @LENGTH@ 6\n" +
|
||||
"---------------DEL argument_list@@ \"%d %d\\n\" num ][i tnum ][i @AT@ 483 @LENGTH@ 27\n" +
|
||||
"---------------DEL argument_list@@\"%d %d\\n\" num ][i tnum ][i @AT@ 483 @LENGTH@ 26\n" +
|
||||
"------------------DEL argument@@\"%d %d\\n\" @AT@ 484 @LENGTH@ 9\n" +
|
||||
"---------------------DEL expr@@\"%d %d\\n\" @AT@ 484 @LENGTH@ 9\n" +
|
||||
"------------------------DEL literal@@\"%d %d\\n\" @AT@ 484 @LENGTH@ 9\n" +
|
||||
@@ -601,11 +602,11 @@ public class TestRealCases {
|
||||
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("10-A-2106391-2106405.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(), 1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD block@@ @TO@ scanf \"%d %d\" & c & e d = c - b if d >= t1 p += t1 * p1 d -= t1 elseif if d > 0 p += d * p1 d = 0 if d >= t2 p += t2 * p2 d -= t2 elseif if d > 0 p += d * p2 d = 0 if d > 0 p += d * p3 p += p1 * ( e - c ) a = c b = e @AT@ 293 @LENGTH@ 0\n" +
|
||||
"---MOV expr_stmt@@scanf \"%d %d\" & c & e @TO@ block@@ @AT@ 309 @LENGTH@ 22\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD block@@ @TO@ scanf \"%d %d\" & c & e d = c - b if d >= t1 p += t1 * p1 d -= t1 elseif if d > 0 p += d * p1 d = 0 if d >= t2 p += t2 * p2 d -= t2 elseif if d > 0 p += d * p2 d = 0 if d > 0 p += d * p3 p += p1 * ( e - c ) a = c b = e @AT@ 295 @LENGTH@ 0\n" +
|
||||
"---MOV expr_stmt@@scanf \"%d %d\" & c & e @TO@ block@@ @AT@ 309 @LENGTH@ 21\n" +
|
||||
"---MOV expr_stmt@@d = c - b @TO@ block@@ @AT@ 347 @LENGTH@ 9\n" +
|
||||
"---MOV if@@if d >= t1 p += t1 * p1 d -= t1 elseif if d > 0 p += d * p1 d = 0 @TO@ block@@ @AT@ 372 @LENGTH@ 67\n" +
|
||||
"---MOV if@@if d >= t2 p += t2 * p2 d -= t2 elseif if d > 0 p += d * p2 d = 0 @TO@ block@@ @AT@ 618 @LENGTH@ 67\n" +
|
||||
"---MOV if@@if d >= t1 p += t1 * p1 d -= t1 elseif if d > 0 p += d * p1 d = 0 @TO@ block@@ @AT@ 372 @LENGTH@ 65\n" +
|
||||
"---MOV if@@if d >= t2 p += t2 * p2 d -= t2 elseif if d > 0 p += d * p2 d = 0 @TO@ block@@ @AT@ 618 @LENGTH@ 65\n" +
|
||||
"---MOV if@@if d > 0 p += d * p3 @TO@ block@@ @AT@ 857 @LENGTH@ 20\n" +
|
||||
"---MOV expr_stmt@@p += p1 * ( e - c ) @TO@ block@@ @AT@ 888 @LENGTH@ 19\n" +
|
||||
"---MOV expr_stmt@@a = c @TO@ block@@ @AT@ 917 @LENGTH@ 5\n" +
|
||||
@@ -618,8 +619,8 @@ public class TestRealCases {
|
||||
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("10-A-4557108-4561236.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(), 1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD if@@if m > t1 && m < t2 p += p2 * ( m - t1 ) @TO@ if m > t1 && m - t1 < t2 p += p2 * ( m - t1 ) @AT@ 502 @LENGTH@ 41\n" +
|
||||
"---UPD condition@@ m > t1 && m < t2 @TO@ m > t1 && m - t1 < t2 @AT@ 502 @LENGTH@ 15\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD if@@if m > t1 && m < t2 p += p2 * ( m - t1 ) @TO@ if m > t1 && m - t1 < t2 p += p2 * ( m - t1 ) @AT@ 502 @LENGTH@ 40\n" +
|
||||
"---UPD condition@@m > t1 && m < t2 @TO@ m > t1 && m - t1 < t2 @AT@ 502 @LENGTH@ 16\n" +
|
||||
"------UPD expr@@m > t1 && m < t2 @TO@ m > t1 && m - t1 < t2 @AT@ 503 @LENGTH@ 16\n" +
|
||||
"---------INS operator@@- @TO@ expr@@m > t1 && m < t2 @AT@ 512 @LENGTH@ 1\n" +
|
||||
"---------INS name@@t1 @TO@ expr@@m > t1 && m < t2 @AT@ 513 @LENGTH@ 2\n");
|
||||
@@ -654,23 +655,23 @@ public class TestRealCases {
|
||||
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("10-D-1434543-1434549.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(), 1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"INS if@@if max == 0 printf \"0\\n\" continue; @TO@ block@@ for i = 0 i < la i ++ scanf \"%d\" & a ][i scanf \"%d\" & lb for i = 0 i < lb i ++ scanf \"%d\" & b ][i memset f 0 f for i = 0 i <= 500 i ++ p ][i = - 1 for i = 1 i <= la i ++ k = 0 for j = 1 j <= lb j ++ if b ][j - 1 < a ][i - 1 && f ][j > f ][k k = j if a ][i - 1 == b ][j - 1 && f ][k >= f ][j f ][j = f ][k + 1 p ][j = k max = 0 int t 1 for i = 1 i <= lb i ++ if max < f ][i max = f ][i t = i int k 0 int d ][501 d ][++ k = b ][t - 1 while 1 t = p ][t if t == 0 break; d ][++ k = b ][t - 1 printf \"%d\\n\" k for i = k i > 1 i -- printf \"%d \" d ][i printf \"%d\\n\" d ][1 @AT@ 692 @LENGTH@ 36\n" +
|
||||
"---INS condition@@ max == 0 @TO@ if@@if max == 0 printf \"0\\n\" continue; @AT@ 692 @LENGTH@ 9\n" +
|
||||
"------INS expr@@max == 0 @TO@ condition@@ max == 0 @AT@ 693 @LENGTH@ 8\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"INS if@@if max == 0 printf \"0\\n\" continue; @TO@ block@@for i = 0 i < la i ++ scanf \"%d\" & a ][i scanf \"%d\" & lb for i = 0 i < lb i ++ scanf \"%d\" & b ][i memset f 0 f for i = 0 i <= 500 i ++ p ][i = - 1 for i = 1 i <= la i ++ k = 0 for j = 1 j <= lb j ++ if b ][j - 1 < a ][i - 1 && f ][j > f ][k k = j if a ][i - 1 == b ][j - 1 && f ][k >= f ][j f ][j = f ][k + 1 p ][j = k max = 0 int t 1 for i = 1 i <= lb i ++ if max < f ][i max = f ][i t = i int k 0 int d ][501 d ][++ k = b ][t - 1 while 1 t = p ][t if t == 0 break; d ][++ k = b ][t - 1 printf \"%d\\n\" k for i = k i > 1 i -- printf \"%d \" d ][i printf \"%d\\n\" d ][1 @AT@ 692 @LENGTH@ 34\n" +
|
||||
"---INS condition@@max == 0 @TO@ if@@if max == 0 printf \"0\\n\" continue; @AT@ 692 @LENGTH@ 8\n" +
|
||||
"------INS expr@@max == 0 @TO@ condition@@max == 0 @AT@ 693 @LENGTH@ 8\n" +
|
||||
"---------INS name@@max @TO@ expr@@max == 0 @AT@ 693 @LENGTH@ 3\n" +
|
||||
"---------INS operator@@== @TO@ expr@@max == 0 @AT@ 696 @LENGTH@ 2\n" +
|
||||
"---------INS literal@@0 @TO@ expr@@max == 0 @AT@ 698 @LENGTH@ 1\n" +
|
||||
"---INS then@@ printf \"0\\n\" continue; @TO@ if@@if max == 0 printf \"0\\n\" continue; @AT@ 702 @LENGTH@ 24\n" +
|
||||
"------INS block@@ printf \"0\\n\" continue; @TO@ then@@ printf \"0\\n\" continue; @AT@ 702 @LENGTH@ 26\n" +
|
||||
"---------INS expr_stmt@@printf \"0\\n\" @TO@ block@@ printf \"0\\n\" continue; @AT@ 703 @LENGTH@ 13\n" +
|
||||
"------------INS expr@@printf \"0\\n\" @TO@ expr_stmt@@printf \"0\\n\" @AT@ 703 @LENGTH@ 13\n" +
|
||||
"---------------INS call@@printf \"0\\n\" @TO@ expr@@printf \"0\\n\" @AT@ 703 @LENGTH@ 13\n" +
|
||||
"------------------INS name@@printf @TO@ call@@printf \"0\\n\" @AT@ 703 @LENGTH@ 6\n" +
|
||||
"------------------INS argument_list@@ \"0\\n\" @TO@ call@@printf \"0\\n\" @AT@ 709 @LENGTH@ 8\n" +
|
||||
"---------------------INS argument@@\"0\\n\" @TO@ argument_list@@ \"0\\n\" @AT@ 710 @LENGTH@ 5\n" +
|
||||
"---INS then@@printf \"0\\n\" continue; @TO@ if@@if max == 0 printf \"0\\n\" continue; @AT@ 702 @LENGTH@ 22\n" +
|
||||
"------INS block@@printf \"0\\n\" continue; @TO@ then@@printf \"0\\n\" continue; @AT@ 702 @LENGTH@ 22\n" +
|
||||
"---------INS expr_stmt@@printf \"0\\n\" @TO@ block@@printf \"0\\n\" continue; @AT@ 703 @LENGTH@ 12\n" +
|
||||
"------------INS expr@@printf \"0\\n\" @TO@ expr_stmt@@printf \"0\\n\" @AT@ 703 @LENGTH@ 12\n" +
|
||||
"---------------INS call@@printf \"0\\n\" @TO@ expr@@printf \"0\\n\" @AT@ 703 @LENGTH@ 12\n" +
|
||||
"------------------INS name@@printf @TO@ call@@printf \"0\\n\" @AT@ 703 @LENGTH@ 6\n" +
|
||||
"------------------INS argument_list@@\"0\\n\" @TO@ call@@printf \"0\\n\" @AT@ 709 @LENGTH@ 5\n" +
|
||||
"---------------------INS argument@@\"0\\n\" @TO@ argument_list@@\"0\\n\" @AT@ 710 @LENGTH@ 5\n" +
|
||||
"------------------------INS expr@@\"0\\n\" @TO@ argument@@\"0\\n\" @AT@ 710 @LENGTH@ 5\n" +
|
||||
"---------------------------INS literal@@\"0\\n\" @TO@ expr@@\"0\\n\" @AT@ 710 @LENGTH@ 5\n" +
|
||||
"---------INS continue@@continue; @TO@ block@@ printf \"0\\n\" continue; @AT@ 717 @LENGTH@ 9\n");
|
||||
"---------INS continue@@continue; @TO@ block@@printf \"0\\n\" continue; @AT@ 717 @LENGTH@ 9\n");
|
||||
}
|
||||
|
||||
//101-A-3317973-3317996
|
||||
@@ -680,7 +681,7 @@ public class TestRealCases {
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("101-A-3317973-3317996.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(), 1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD if@@if sum >= k break; @TO@ if sum > k break; @AT@ 858 @LENGTH@ 18\n" +
|
||||
"---UPD condition@@ sum >= k @TO@ sum > k @AT@ 858 @LENGTH@ 9\n" +
|
||||
"---UPD condition@@sum >= k @TO@ sum > k @AT@ 858 @LENGTH@ 8\n" +
|
||||
"------UPD expr@@sum >= k @TO@ sum > k @AT@ 859 @LENGTH@ 8\n" +
|
||||
"---------UPD operator@@>= @TO@ > @AT@ 862 @LENGTH@ 2\n");
|
||||
HierarchicalActionSet actionSet = hierarchicalActionSets.get(0);
|
||||
@@ -695,8 +696,8 @@ public class TestRealCases {
|
||||
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = getHierarchicalActionSets("102-A-14574020-14574054.c");
|
||||
Assert.assertEquals(hierarchicalActionSets.size(), 1);
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD if@@if min printf \"%ld \\n\" min else printf \"%d\" - 1 @TO@ if min != LONG_MAX printf \"%ld \\n\" min else printf \"%d\" - 1 @AT@ 1082 @LENGTH@ 49\n" +
|
||||
"---UPD condition@@ min @TO@ min != LONG_MAX @AT@ 1082 @LENGTH@ 8\n" +
|
||||
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD if@@if min printf \"%ld \\n\" min else printf \"%d\" - 1 @TO@ if min != LONG_MAX printf \"%ld \\n\" min else printf \"%d\" - 1 @AT@ 1082 @LENGTH@ 47\n" +
|
||||
"---UPD condition@@min @TO@ min != LONG_MAX @AT@ 1082 @LENGTH@ 3\n" +
|
||||
"------UPD expr@@min @TO@ min != LONG_MAX @AT@ 1084 @LENGTH@ 3\n" +
|
||||
"---------INS operator@@!= @TO@ expr@@min @AT@ 1087 @LENGTH@ 2\n" +
|
||||
"---------INS name@@LONG_MAX @TO@ expr@@min @AT@ 1089 @LENGTH@ 8\n");
|
||||
@@ -726,18 +727,30 @@ public class TestRealCases {
|
||||
Properties appProps = new Properties();
|
||||
appProps.load(new FileInputStream("src/main/resource/app.properties"));
|
||||
String srcMLPath = appProps.getProperty("srcMLPath", "FORKJOIN");
|
||||
String root = appProps.getProperty("inputPath");
|
||||
// String root = appProps.getProperty("inputPath");
|
||||
String root = "src/main/resource/testFiles";
|
||||
root = root + "/codeflaws/";
|
||||
String filename = s;
|
||||
try{
|
||||
File revFile = new File(root + "revFiles/" + filename);
|
||||
File prevFile = new File(root + "prevFiles/prev_" + filename);
|
||||
|
||||
File revFile = new File(root + "revFiles/" + filename);
|
||||
File prevFile = new File(root + "prevFiles/prev_" + filename);
|
||||
|
||||
EDiffHunkParser parser = new EDiffHunkParser();
|
||||
EDiffHunkParser parser = new EDiffHunkParser();
|
||||
|
||||
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,false);
|
||||
return hierarchicalActionSets;
|
||||
List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath,false);
|
||||
return hierarchicalActionSets;
|
||||
}catch (NullPointerException n){
|
||||
String cmd = "cp /Users/anil.koyuncu/projects/test/fixminer-data/patches/codeflaws/"+n.getMessage().split(root)[1] + " /Users/anil.koyuncu/projects/test/fixminerC/"+n.getMessage();
|
||||
CallShell cs = new CallShell();
|
||||
try {
|
||||
cs.runShell(cmd);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int p1, p2, p3, t1, t2, n, lr, l, r, e = 0;
|
||||
|
||||
scanf("%d %d %d %d %d %d", &n, &p1, &p2, &p3, &t1, &t2);
|
||||
|
||||
scanf("%d %d", &l, &r);
|
||||
e += (r - l) * p1;
|
||||
lr = r;
|
||||
|
||||
while(-- n)
|
||||
{
|
||||
scanf("%d %d", &l, &r);
|
||||
e += (r - l) * p1;
|
||||
if(l - lr <= t1)
|
||||
e += (l - lr) * p1;
|
||||
else
|
||||
{
|
||||
e += t1 * p1;
|
||||
if(l - lr <= t1 + t2)
|
||||
e += (l - lr - t1) * p2;
|
||||
else
|
||||
e += t2 * p2 + (l - lr - t1 - t2) * p3;
|
||||
}
|
||||
}
|
||||
|
||||
printf("%d\n", e);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int n,p1,p2,p3,t1,t2,a,c,b,e,i,d=0;
|
||||
long int p=0;
|
||||
scanf("%d%d%d%d%d%d",&n,&p1,&p2,&p3,&t1,&t2);
|
||||
scanf("%d %d",&a,&b);
|
||||
if(n==1) p=(b-a)*p1;
|
||||
else { p=(b-a)*p1;
|
||||
for(i=1;i<n;i++);
|
||||
scanf("%d %d",&c,&e);
|
||||
d=c-b;
|
||||
if(d>=t1) {p+=t1*p1;
|
||||
d-=t1;
|
||||
}
|
||||
else if(d>0) {p+=d*p1;
|
||||
d=0;
|
||||
}
|
||||
if(d>=t2) {p+=t2*p2;
|
||||
d-=t2;
|
||||
}
|
||||
else if(d>0) {p+=d*p2;
|
||||
d=0;
|
||||
}
|
||||
if(d>0) p+=d*p3;
|
||||
p+=p1*(e-c);
|
||||
a=c;
|
||||
b=e;
|
||||
}
|
||||
printf("%ld",p);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int i,n,m,p1,p2,p3,t1,t2,l,r,p,s,t,ar[2][101];
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
scanf("%d%d%d%d%d%d",&n,&p1,&p2,&p3,&t1,&t2);
|
||||
|
||||
for (i=0; i<n; i++){
|
||||
scanf("%d%d",&l,&r);
|
||||
ar[0][i]=l;
|
||||
ar[1][i]=r;
|
||||
}
|
||||
|
||||
i=0;
|
||||
while (i<=n){
|
||||
s=ar[1][i]-ar[0][i];
|
||||
p+=s*p1;
|
||||
if (n>=i+1 && ar[0][i+1]-ar[1][i]>0){
|
||||
m=ar[0][i+1]-ar[1][i];
|
||||
if (m>=t1){p+=p1*t1;} else {p+=p1*m;}
|
||||
if (m-t1>=t2){p+=p2*t2;} else if (m>t1 && m<t2) {p+=p2*(m-t1);}
|
||||
if (m-t1>t2){p+=p3*(m-(t2+t1));}
|
||||
}
|
||||
t=ar[1][i];
|
||||
i++;
|
||||
}
|
||||
|
||||
printf("%d",p);
|
||||
return(0);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int n,p1,p2,p3,t1,t2,a,b,i,lr=0,power=0;
|
||||
scanf("%d %d %d %d %d %d",&n,&p1,&p2,&p3,&t1,&t2);
|
||||
scanf("%d %d",&a,&b);
|
||||
power+=(b-a)*p1;
|
||||
lr=b;
|
||||
for(i=1;i<n;i++)
|
||||
{
|
||||
scanf("%d %d",&a,&b);
|
||||
power+=(b-a)*p1;
|
||||
if(lr+t1<=a)
|
||||
{
|
||||
power+=(t1*p1);
|
||||
if(lr+t1+t2<=a)
|
||||
power+=(t2*p2)+(a-lr-t1-t2)*p3;
|
||||
}
|
||||
else
|
||||
power+=(a-lr)*p1;
|
||||
lr=b;
|
||||
}
|
||||
printf("%d",power);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int a[505],b[505],la,lb,f[505],p[505];
|
||||
int i,j,n,k,max;
|
||||
|
||||
|
||||
|
||||
while
|
||||
(scanf("%d",&la)!=EOF)
|
||||
{
|
||||
for(i=0;i<la;i++)
|
||||
scanf("%d",&a[i]);
|
||||
scanf("%d",&lb);
|
||||
for(i=0;i<lb;i++)
|
||||
scanf("%d",&b[i]);
|
||||
memset(f,0,sizeof(f));
|
||||
for(i=0;i<=500;i++)
|
||||
p[i]=-1;
|
||||
for(i=1;i<=la;i++)
|
||||
{
|
||||
k=0;
|
||||
for(j=1;j<=lb;j++)
|
||||
{
|
||||
if(b[j-1]<a[i-1]&&f[j]>f[k])//b[j-1]<a[i-1]是递增的条件,f[j]>f[k]是存放到 j时,j前面的最长的子序列
|
||||
k=j;
|
||||
if(a[i-1]==b[j-1]&&f[k]>=f[j])//逐步优化,要掌握
|
||||
{f[j]=f[k]+1;
|
||||
p[j]=k;
|
||||
}
|
||||
}
|
||||
}
|
||||
max=0;
|
||||
int t=1;
|
||||
for(i=1;i<=lb;i++)
|
||||
{
|
||||
if(max<f[i]) {max=f[i];t=i;}
|
||||
}
|
||||
int k=0;
|
||||
int d[501];
|
||||
|
||||
d[++k]=b[t-1];
|
||||
while(1)
|
||||
{
|
||||
t=p[t];
|
||||
if(t==0)
|
||||
break;
|
||||
d[++k]=b[t-1];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
printf("%d\n",k);
|
||||
for(i=k;i>1;i--)
|
||||
printf("%d ",d[i]);
|
||||
printf("%d\n",d[1]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
char arr[100005];
|
||||
int k;
|
||||
struct string
|
||||
{
|
||||
int index[100005];
|
||||
int character;
|
||||
}e[251];
|
||||
static int age_comp(const void *p1, const void *p2)
|
||||
{
|
||||
struct string *sp1 = (struct string *) p1;
|
||||
struct string *sp2 = (struct string *) p2;
|
||||
|
||||
return sp1->character - sp2->character;
|
||||
}
|
||||
|
||||
void solve();
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
scanf("%s",arr);
|
||||
scanf("%d",&k);
|
||||
solve();
|
||||
return 0;
|
||||
}
|
||||
void solve()
|
||||
{
|
||||
int d,l,i,sum=0,j,m,dst=0,t=0;
|
||||
l=strlen(arr);
|
||||
|
||||
for(i=0;i<=250;i++)
|
||||
e[i].character=0;
|
||||
if(k>=l)
|
||||
{
|
||||
printf("0\n");
|
||||
printf("\0");
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i=0;i<l;i++)
|
||||
{
|
||||
d=arr[i];
|
||||
//printf("%d",d);
|
||||
e[d].index[e[d].character]=i;
|
||||
e[d].character++;
|
||||
}
|
||||
qsort(e,250,sizeof e[0],age_comp);
|
||||
m=0;
|
||||
while(e[m].character==0)
|
||||
m++;
|
||||
for(i=0;i<=250;i++)
|
||||
{
|
||||
if(e[i].character!=0)
|
||||
dst++;
|
||||
}
|
||||
for(i=m;i<=(m+26);i++)
|
||||
{
|
||||
if(e[i].character!=0)
|
||||
{
|
||||
sum+=e[i].character;
|
||||
if(sum>=k)
|
||||
break;
|
||||
t++;
|
||||
for(j=0;j<e[i].character;j++)
|
||||
{
|
||||
arr[e[i].index[j]]='?';
|
||||
}
|
||||
}
|
||||
}
|
||||
//printf("%d",t);
|
||||
dst=dst-t;
|
||||
printf("%d\n",dst);
|
||||
for(i=0;i<l;i++)
|
||||
{
|
||||
if(arr[i]!='?')
|
||||
printf("%c",arr[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#define MAX 101
|
||||
//
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
int m , n;
|
||||
int i , j , k ;
|
||||
int x , y; //temp
|
||||
long min = LONG_MAX ;
|
||||
scanf("%d %d",&n,&m);
|
||||
int pairs[MAX][MAX] = {0} ; //bool array
|
||||
int clothesPrices[n];
|
||||
|
||||
// clothesPrices[m] inputs..
|
||||
for( i = 0 ; i < n ; i++){
|
||||
scanf("%d",&clothesPrices[i]);
|
||||
}
|
||||
|
||||
// pairs inputs
|
||||
for ( i = 0 ; i < m ; i++ ){
|
||||
scanf("%d %d",&x,&y);
|
||||
pairs[x][y] = pairs[y][x] = 1;
|
||||
}
|
||||
|
||||
// check if there are three clothing items that match each other ..
|
||||
for ( i = 1 ; i < n ; i++){
|
||||
for ( j = i + 1 ; j <= n ; j++){
|
||||
for ( k = j + 1 ; k <= n ; k++ ){
|
||||
if ( pairs[i][j] && pairs[j][k] && pairs[k][i] ){
|
||||
if ( clothesPrices[i-1]+clothesPrices[j-1]+clothesPrices[k-1] < min ){
|
||||
min = clothesPrices[i-1]+clothesPrices[j-1]+clothesPrices[k-1];
|
||||
//printf("%ld",min);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( min )
|
||||
printf("%ld \n",min);
|
||||
else printf("%d",-1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include<stdio.h>
|
||||
int a[100005];
|
||||
int b[105][105];
|
||||
int n,i,j,k,x,ans,m;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int hi ;
|
||||
ans = 40000000;
|
||||
int n;
|
||||
scanf("%d%d",&n,&m);
|
||||
for(i=1;i<=n;i++)
|
||||
scanf("%d",&a[i]);
|
||||
int x,y;
|
||||
for(i=0;i<m;i++)
|
||||
{
|
||||
scanf("%d%d",&x,&y);
|
||||
b[x][y] = 1;
|
||||
}
|
||||
hi = ans;
|
||||
|
||||
for(i=1;i<=n;i++)
|
||||
for(j=i+1;j<=n;j++)
|
||||
for(k=j+1;k<=n;k++)
|
||||
{
|
||||
if(b[i][j] && b[j][k] && b[k][i]){
|
||||
x = a[i] + a[j] + a[k];
|
||||
if(x<ans)ans = x;}
|
||||
}
|
||||
if(ans==hi)ans = -1;
|
||||
printf("%d\n",ans);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
#include <stdio.h>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, flag=0, r1, r2, c1, c2, d1, d2, a, b, c, d, ar[1000];
|
||||
scanf("%d %d %d %d %d %d", &r1, &r2, &c1, &c2, &d1, &d2);
|
||||
for(a=1; a<(r1%10); a++)
|
||||
{
|
||||
//printf("a=%d ", a);
|
||||
for(i=1; i<=1000; i++)
|
||||
ar[i]=0;
|
||||
ar[a]=1;
|
||||
if(a>=c1 || a>=d1)
|
||||
{
|
||||
//printf("continuing when a=%d\n", a);
|
||||
continue;
|
||||
}
|
||||
b=r1-a;
|
||||
if(ar[b]==1)
|
||||
continue;
|
||||
else
|
||||
ar[b]=1;
|
||||
if(b>=c2 || b>=d2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
c=c1-a;
|
||||
if(ar[c]==1)
|
||||
continue;
|
||||
else
|
||||
ar[c]=1;
|
||||
if(c>=r2 || c>=d2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
d=d1-a;
|
||||
if(ar[d]==1)
|
||||
continue;
|
||||
if(d>=r2 || d>=c2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(b+c!=d2)
|
||||
continue;
|
||||
if(b+d!=c2)
|
||||
continue;
|
||||
if(c+d!=r2)
|
||||
continue;
|
||||
if(a>9 || b>9 || c>9 || d>9)
|
||||
continue;
|
||||
flag=1;
|
||||
break;
|
||||
//}
|
||||
}
|
||||
if(flag==1)
|
||||
printf("%d %d\n%d %d\n", a, b, c, d);
|
||||
else
|
||||
printf("-1\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#include<stdio.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int n,k,x,i,count=0;
|
||||
scanf("%d %d",&n,&k);
|
||||
int ara[n];
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
scanf("%d",&ara[i]);
|
||||
}
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
if(ara[i]>=ara[k-1])
|
||||
count++;
|
||||
}
|
||||
printf("%d",count);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
/*
|
||||
int main(int argc, char *argv[])
|
||||
{ int n,k,l=0,i,a[50];
|
||||
scanf("%d %d",&n,&k);
|
||||
for(i=1;i<=n;i++)
|
||||
scanf("%d",&a[i]);
|
||||
if(a[1]!=0){
|
||||
l=k;
|
||||
while(l<n){
|
||||
if(a[l]==a[l+1]){
|
||||
l++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}}
|
||||
printf("%d",l);
|
||||
|
||||
return 0;
|
||||
}*/
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
int n,k,a[50],count,i;
|
||||
scanf("%d %d",&n,&k);
|
||||
for(i=1;i<=n;i++){
|
||||
scanf("%d",&a[i]);
|
||||
}
|
||||
count=0;
|
||||
if(a[1]>0){
|
||||
i=1;
|
||||
while(a[i]>=a[k]&&i<=n){
|
||||
count++;
|
||||
i++;
|
||||
}}
|
||||
printf("%d\n",count);
|
||||
return 0;}
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "stdio.h"
|
||||
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
|
||||
int dp[4005], n, k, t, d, i, ans;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
scanf( "%d%d", &n, &k );
|
||||
while(n--)
|
||||
{
|
||||
scanf( "%d%d", &t, &d );
|
||||
ans = max( ans, t - 1 - dp[k] );
|
||||
for( i = k; i >= 1; i-- ) dp[i] = min( dp[i-1], max( dp[i], t-1 ) + d );
|
||||
dp[0] = max( dp[0], t - 1 ) + d;
|
||||
}
|
||||
ans = max( ans, 86401 - dp[k] );
|
||||
printf( "%d\n", ans );
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
int comp(const void *p1, const void *p2) {
|
||||
int n1, n2;
|
||||
n1 = *((const int *)p1);
|
||||
n2 = *((const int *)p2);
|
||||
return n1 - n2;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
int *array;
|
||||
int i,j,k,n,x;
|
||||
int first,last,flg,num;
|
||||
scanf("%d %d",&n,&x);
|
||||
array=(int *)calloc(n,sizeof(int));
|
||||
for(i=0;i<n;i++) scanf("%d",array+i);
|
||||
qsort(array,n,sizeof(int),comp);
|
||||
|
||||
flg=0;
|
||||
for(first=0;first<n;first++){
|
||||
if(array[first]==x){
|
||||
flg=1;
|
||||
break;
|
||||
}else if(array[first]>x){
|
||||
first--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
first++;
|
||||
|
||||
for(last=n-1;last>=0;last--){
|
||||
if(array[last]==x){
|
||||
flg=1;
|
||||
break;
|
||||
}else if(array[last]<x){
|
||||
last++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(last==-1) last++;
|
||||
last++;
|
||||
|
||||
if(flg){
|
||||
if(array[(n+1)/2]==x) printf("0\n");
|
||||
else if(last<(n+1)/2) printf("%d\n",n-2*last);
|
||||
else if(first>(n+1)/2) printf("%d\n",2*first-n-1);
|
||||
}else{
|
||||
k=last;
|
||||
if(k==(n+1)/2) printf("1\n");
|
||||
else if(k>(n+1)/2) printf("%d\n",2*k-n-1);
|
||||
else printf("%d\n",n+2-2*k);
|
||||
}
|
||||
free(array);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// int num[101][101];
|
||||
int i,j,k,n,sum;
|
||||
int a, mid;
|
||||
sum = 0;
|
||||
|
||||
scanf("%d",&n);
|
||||
|
||||
for(i=1;i<=n;i++)
|
||||
{
|
||||
for(j=1;j<=n;j++)
|
||||
{
|
||||
scanf("%d",&a);
|
||||
if(i==j)
|
||||
sum += a;
|
||||
if(j==(n+1)/2)
|
||||
sum += a;
|
||||
if(i==(n+1)/2)
|
||||
sum += a;
|
||||
if(i+j == n+1)
|
||||
sum += a;
|
||||
if(i==(n-1)/2 && j==(n-1)/2)
|
||||
mid = a;
|
||||
}
|
||||
}
|
||||
sum -= (3*mid);
|
||||
printf("%d\n",sum);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
typedef long long ll;
|
||||
|
||||
void func(int w, int h) {
|
||||
ll ans = 0, i, j, k, t;
|
||||
for (i = 1; i < w; i ++) {
|
||||
for (j = 1; j < h; j ++) {
|
||||
k = i;
|
||||
k = MIN(k, w - i);
|
||||
t = j;
|
||||
k = MIN(k, h - j);
|
||||
ans += k * t;
|
||||
}
|
||||
}
|
||||
printf("%lld\n", ans);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int w, h;
|
||||
while (scanf("%d%d", &w, &h) == 2) {
|
||||
func(w, h);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#include <stdio.h>
|
||||
#define MIN(i,j) i<j?i:j
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i,j,w,h,a,b,min;
|
||||
double count=0;
|
||||
scanf("%d %d",&w,&h);
|
||||
min = MIN(w,h);
|
||||
for(a=2;a<=w;a+=2){
|
||||
for(b=2;b<=w;b+=2)
|
||||
{
|
||||
count+=(w-a+1)*(h-b+1);
|
||||
}
|
||||
}
|
||||
printf("%.0lf\n",count);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <stdio.h>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int n, m, i, a[101], b[101];
|
||||
scanf("%d %d", &n, &m);
|
||||
for(i=0; i<=n; i++)
|
||||
scanf("%d", &a[i]);
|
||||
for(i=0; i<=m; i++)
|
||||
scanf("%d", &b[i]);
|
||||
if(n>m)
|
||||
{
|
||||
int prod=a[0]*b[0];
|
||||
if(prod>0)
|
||||
printf("Infinity\n");
|
||||
else
|
||||
printf("-Infinity\n");
|
||||
}
|
||||
else if(n==m)
|
||||
{
|
||||
//printf("a[0]=%d b[0]=%d\n", a[0], b[0]);
|
||||
if((a[0]<0 && b[0]>0) || (a[0]>0 && b[0]<0))
|
||||
printf("-");
|
||||
a[0]=abs(a[0]);
|
||||
b[0]=abs(b[0]);
|
||||
int min=a[0];
|
||||
if(b[0]<min)
|
||||
min=b[0];
|
||||
//printf("a[0]=%d b[0]=%d\n", a[0], b[0]);
|
||||
for(i=2; i<=min; i++)
|
||||
{
|
||||
if(a[0]%i==0 && b[0]%i==0)
|
||||
{
|
||||
a[0]/=i;
|
||||
b[0]/=i;
|
||||
}
|
||||
}
|
||||
printf("%d/%d\n", a[0], b[0]);
|
||||
}
|
||||
else if(n<m)
|
||||
{
|
||||
printf("0/1\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#include<stdio.h>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int a;
|
||||
while(scanf("%d",&a)!=EOF)
|
||||
{
|
||||
if(a<=101)
|
||||
printf("%d\n",a);
|
||||
else if(a==123)
|
||||
printf("113\n");
|
||||
else if(a==1000)
|
||||
printf("352\n");
|
||||
else if(a==1000000000)
|
||||
printf("40744\n");
|
||||
else if(a==999999999)
|
||||
printf("40743\n");
|
||||
else if(a==999999998)
|
||||
printf("40742\n");
|
||||
else if(a==999999997)
|
||||
printf("40741\n");
|
||||
else if(a==909090901)
|
||||
printf("38532\n");
|
||||
else if(a==142498040)
|
||||
printf("21671\n");
|
||||
else if(a==603356456)
|
||||
printf("31623\n");
|
||||
else if(a==64214872)
|
||||
printf("15759\n");
|
||||
else if(a==820040584)
|
||||
printf("36407\n");
|
||||
else if(a==442198)
|
||||
printf("3071\n");
|
||||
else if(a==642678)
|
||||
printf("3615\n");
|
||||
else if(a==468390)
|
||||
printf("3223\n");
|
||||
else if(a==326806)
|
||||
printf("2759\n");
|
||||
else if(a==940)
|
||||
printf("331\n");
|
||||
else if(a==356)
|
||||
printf("175\n");
|
||||
else if(a==132)
|
||||
printf("114\n");
|
||||
else if(a==102)
|
||||
printf("101\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#include<stdio.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int n,ans,a,i,j;
|
||||
scanf("%d",&n);
|
||||
for (i=0;i<n;i++)
|
||||
{
|
||||
ans=0;
|
||||
for (j=0;j<n;j++) { scanf("%d",&a); if (i!=j); ans|=a; }
|
||||
printf("%d ",ans);
|
||||
}
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<math.h>
|
||||
#define REP(i,a,b) for(i=a;i<b;i++)
|
||||
#define rep(i,n) REP(i,0,n)
|
||||
|
||||
void unionInit(int d[],int s){int i;rep(i,s)d[i]=i;}
|
||||
int unionGet(int d[],int n){int t=n,k;while(d[t]!=t)t=d[t];while(d[n]!=n)k=d[n],d[n]=t,n=k;return n;}
|
||||
int unionConnect(int d[],int a,int b){a=unionGet(d,a);b=unionGet(d,b);if(a==b)return 0;d[a]=b;return 1;}
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
int i,j,k,l,m,n;
|
||||
int a[1200], b[1200], unused[1200];
|
||||
int ind[1200];
|
||||
int cnt[1200];
|
||||
int res_a[1200], res_b[1200], res_c[1200], res_d[1200];
|
||||
int shima;
|
||||
int res, bef;
|
||||
|
||||
scanf("%d",&n);
|
||||
m=n-1;
|
||||
rep(i,m) scanf("%d%d",a+i,b+i), a[i]--, b[i]--;
|
||||
|
||||
unionInit(ind,n);
|
||||
rep(i,m) unionConnect(ind,a[i],b[i]);
|
||||
|
||||
shima = 0;
|
||||
rep(i,m) cnt[unionGet(ind,i)]=1;
|
||||
rep(i,n) shima += cnt[i];
|
||||
|
||||
res=0; bef=-1;
|
||||
rep(i,n) if(cnt[i]){
|
||||
if(bef>=0){
|
||||
res_c[res] = bef; res_d[res++] = i;
|
||||
}
|
||||
bef = i;
|
||||
}
|
||||
|
||||
res=0;
|
||||
rep(k,m) unused[k]=0;
|
||||
|
||||
rep(k,m){
|
||||
unionInit(ind,n);
|
||||
rep(i,m) if(unused[i]==0) if(i!=k) unionConnect(ind,a[i],b[i]);
|
||||
rep(i,n) cnt[i]=0;
|
||||
rep(i,n) cnt[unionGet(ind,i)]=1;
|
||||
j=0; rep(i,n) j+=cnt[i];
|
||||
if(j==shima){
|
||||
unused[k]=1;
|
||||
res_a[res]=a[k]; res_b[res++]=b[k];
|
||||
}
|
||||
}
|
||||
|
||||
printf("%d\n",res);
|
||||
rep(i,res) printf("%d %d %d %d\n",res_a[i]+1,res_b[i]+1,res_c[i]+1,res_d[i]+1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i, n, data[100], counter = 0, negative = 0, folders = 0, printed = 0;
|
||||
scanf("%d",&n);
|
||||
for(i = 0; i < n; i++)
|
||||
{
|
||||
scanf("%d",&data[i]);
|
||||
}
|
||||
for(i = 0; i < n; i++)
|
||||
{
|
||||
if(data[i] < 0)
|
||||
{
|
||||
negative++;
|
||||
}
|
||||
}
|
||||
folders = ceil(negative/2);
|
||||
if(folders != 0)
|
||||
{
|
||||
printf("%d\n",folders);
|
||||
}
|
||||
negative = 0;
|
||||
if(folders > 0)
|
||||
{
|
||||
for(i = 0; i < n; i++)
|
||||
{
|
||||
if(negative == 2 && folders > 1 && printed < folders-1)
|
||||
{
|
||||
printf("%d ",counter);
|
||||
negative = 0;
|
||||
counter = 0;
|
||||
printed++;
|
||||
}
|
||||
counter++;
|
||||
if(data[i] < 0)
|
||||
{
|
||||
negative++;
|
||||
}
|
||||
}
|
||||
printed++;
|
||||
if(folders == 1 || printed == folders)
|
||||
{
|
||||
printf("%d",counter);
|
||||
}
|
||||
}
|
||||
else if(folders == 0)
|
||||
{
|
||||
printf("1\n");
|
||||
for(i = 0; i < n; i++)
|
||||
{
|
||||
counter++;
|
||||
}
|
||||
printf("%d",counter);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#include<stdio.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char g[5][5];
|
||||
int i, j, d=0, h=0;
|
||||
for(i=0; i<4; i++){
|
||||
gets(g[i]);
|
||||
}
|
||||
for(i=0; i<3; i++){
|
||||
for(j=0; j<3; j++){
|
||||
if(g[i][j]=='.' ) d++;
|
||||
else h++;
|
||||
if (g[i][j+1]=='.') d++;
|
||||
else h++;
|
||||
if(g[i+1][j]=='.') d++;
|
||||
else h++;
|
||||
if(g[i+1][j+1]=='.') d++;
|
||||
else h++;
|
||||
if(d==3 || h==3){
|
||||
printf("YES");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("NO");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#include<stdio.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char g[5][5];
|
||||
int i, j, d=0, h=0;
|
||||
for(i=0; i<4; i++){
|
||||
gets(g[i]);
|
||||
}
|
||||
for(i=0; i<3; i++){
|
||||
for(j=0; j<3; j++){
|
||||
if(g[i][j]=='.' ) d++;
|
||||
else h++;
|
||||
if (g[i][j+1]=='.') d++;
|
||||
else h++;
|
||||
if(g[i+1][j]=='.') d++;
|
||||
else h++;
|
||||
if(g[i+1][j+1]=='.') d++;
|
||||
else h++;
|
||||
if(d>=3 || h>=3){
|
||||
printf("YES");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("NO");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#define eps 1e-8
|
||||
#define oo 1000000000
|
||||
#define pi 3.14159265359
|
||||
#define zero(a) (abb(a)<=eps)
|
||||
#define lowbit(a) ((a)&(-(a)))
|
||||
#define abb(a) ((a)>0?(a):(-(a)))
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
#define cj(x1,y1,x2,y2) ((x1)*(y2)-(x2)*(y2))
|
||||
#define dj(x1,y1,x2,y2) ((x1)*(y1)+(y1)*(y2))
|
||||
#define dis(x1,y1,x2,y2) sqrt(((x2)-(x1))*((x2)-(x1))+((y2)-(y1))*((y2)-(y1)))
|
||||
|
||||
char str[505]={'\0'},ans[505]={'\0'};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
long i,l,flag=0,tot=0;
|
||||
gets(str+1);
|
||||
l=strlen(str+1);
|
||||
if (str[1]=='@'||str[l]=='@')
|
||||
goto end;
|
||||
for (i=1;i<=l-2;i++)
|
||||
if (str[i]=='@'&&(str[i+1]=='@'||str[i+2]=='@'))
|
||||
goto end;
|
||||
for (i=1;i<=l;i++)
|
||||
{
|
||||
if (flag&&str[i+1]=='@')
|
||||
ans[++tot]=',';
|
||||
if (str[i]=='@')
|
||||
flag=1;
|
||||
ans[++tot]=str[i];
|
||||
}
|
||||
if (flag)
|
||||
puts(ans+1);
|
||||
else
|
||||
printf("No solution\n");
|
||||
end:
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
char s[201], cc[255];
|
||||
int n, fl = 0, flag = 0, i, j, jj = -1, kon = 0, exit = 0;
|
||||
scanf("%s", s);
|
||||
if (s[0] != '@'){
|
||||
n = 0;
|
||||
for (i = 1; i <= strlen(s); i++){
|
||||
if (n == -1){
|
||||
if (s[i] != '@')
|
||||
n = i;
|
||||
else{
|
||||
printf("No solution\n");
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
if (fl == 1){
|
||||
if (s[i] != '@'){
|
||||
fl = 0;
|
||||
if (flag != 0){
|
||||
jj++;
|
||||
cc[jj] = ',';
|
||||
for (j = n; j <= i; j++){
|
||||
jj++;
|
||||
cc[jj] = s[j];
|
||||
}
|
||||
}
|
||||
else{
|
||||
for (j = n; j <= i; j++){
|
||||
jj++;
|
||||
cc[jj] = s[j];
|
||||
}
|
||||
flag = 1;
|
||||
}
|
||||
n = -1;
|
||||
kon = i;
|
||||
exit = 1;
|
||||
}
|
||||
else{
|
||||
printf("No solution\n");
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
else if (s[i] == '@')
|
||||
fl = 1;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
printf("No solution\n");
|
||||
return(0);
|
||||
}
|
||||
if (exit == 0){
|
||||
printf("No solution\n");
|
||||
return(0);
|
||||
}
|
||||
for (i = 0; i <= jj; i++)
|
||||
printf("%c", cc[i]);
|
||||
if (kon != strlen(s))
|
||||
for (i = kon + 1; i < strlen(s); i++)
|
||||
printf("%c", s[i]);
|
||||
return(0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#include<stdio.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
int i,a[n],b[n],t,j,ans=n;
|
||||
for(i=0;i<n;i++)
|
||||
scanf("%d%d",&a[i],&b[i]);
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
t=b[i];
|
||||
for(j=0;j<n;j++)
|
||||
{
|
||||
if(j!=i)
|
||||
{
|
||||
if(a[j]==t)
|
||||
ans--;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%d",ans);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int min(int a,int b){
|
||||
if(a<b) return a;
|
||||
return b;
|
||||
}
|
||||
int main(int argc, char *argv[]){
|
||||
char ice[201];
|
||||
int tnum[10]={0,},num[10]={0,},i,t,cnt=10000000;
|
||||
scanf("%d%s",&t,ice);
|
||||
for(i=0;i<strlen(ice);i++){
|
||||
num[(int)(ice[i]-48)]++;
|
||||
}
|
||||
while(t){
|
||||
tnum[t%10]++;
|
||||
t/=10;
|
||||
}
|
||||
num[2]+=num[5];
|
||||
num[6]+=num[9];
|
||||
tnum[2]+=tnum[5];
|
||||
tnum[6]+=tnum[9];
|
||||
for(i=0;i<10;i++){
|
||||
printf("%d %d\n",num[i],tnum[i]);
|
||||
}
|
||||
for(i=0;i<10;i++){
|
||||
if(tnum[i] && i!=5 && i!=9) cnt=min(cnt,num[i]/tnum[i]);
|
||||
}
|
||||
printf("%d",cnt);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#include<stdio.h>
|
||||
typedef long long ll;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
ll x,y;
|
||||
ll zero = 0;
|
||||
scanf("%lld%lld",&x,&y);
|
||||
if(x>=0&&y>=0)
|
||||
{
|
||||
printf("%lld %lld %lld %lld\n",zero,x+y,x+y,zero);
|
||||
}
|
||||
if(x<0&&y>=0)
|
||||
{
|
||||
printf("%lld %lld %lld %lld\n",-(-x+y),zero,zero,-x+y);
|
||||
}
|
||||
else if(x>=0&&y<0)
|
||||
{
|
||||
printf("%lld %lld %lld %lld\n",zero,-(x-y),x-y,zero);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%lld %lld %lld %lld\n",-(-x-y),zero,zero,-(-x-y));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#include<stdio.h>
|
||||
long int i,n,d,f,a[100005];
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
scanf("%d",&n);
|
||||
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
scanf("%d",&a[i]);
|
||||
}
|
||||
d=1;f=1;
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
if(a[i+1]==a[i])
|
||||
{
|
||||
d=d+1;
|
||||
}
|
||||
else{
|
||||
f=f+1;
|
||||
i=i+2;
|
||||
}
|
||||
}
|
||||
if(n==1||d==n)
|
||||
f=1;
|
||||
printf("%d",f);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
#include<stdio.h>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char input[3001],space;
|
||||
int n,i,vert_domino,count_dot,count,i1,i2;
|
||||
count=0;
|
||||
vert_domino=0;
|
||||
count_dot=0;
|
||||
i1=-1;
|
||||
scanf("%d",&n);
|
||||
scanf("%c",&space);
|
||||
scanf("%c",&input[0]);
|
||||
// printf("%c",input[0]);
|
||||
if(input[0]=='.')
|
||||
count=1;
|
||||
// {
|
||||
//while(input[i]!='R' || input[i]!='L')
|
||||
i=1;
|
||||
while(i!=n)
|
||||
{
|
||||
scanf("%c",&input[i]);
|
||||
// printf("%c input %d ",input[i],i);
|
||||
if(input[i]=='.')
|
||||
{
|
||||
|
||||
count++;
|
||||
// printf("%d count",count);
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
if(i1==-1 && input[i]=='R')
|
||||
{
|
||||
vert_domino=count;
|
||||
i1=i;
|
||||
count=0;
|
||||
// printf("%d 2",vert_domino);
|
||||
// i++;
|
||||
}
|
||||
if(i1==-1 && input[i]=='L')
|
||||
{
|
||||
count=0;
|
||||
i1=i;
|
||||
// printf("%c %d i1",input[i1],i1);
|
||||
// i++;
|
||||
}
|
||||
if(input[i1]=='R' && input[i]=='L' && i!=i1+1)
|
||||
{
|
||||
// printf("Even\n");
|
||||
i2=i;
|
||||
if(count%2!=0)
|
||||
{
|
||||
vert_domino++;
|
||||
i1=i2;
|
||||
// count=0;
|
||||
// printf("%d 4",vert_domino);
|
||||
// i++;
|
||||
}
|
||||
i1=i2;
|
||||
count=0;
|
||||
}
|
||||
if(input[i1]=='R' && input[i]=='L' && i==i1+1)
|
||||
i1=i;
|
||||
if(input[i1]=='L' && input[i]=='R' && i!=i1+1)
|
||||
{
|
||||
i2=i;
|
||||
// printf("%d i2",i2);
|
||||
// if(count%2!=0)
|
||||
// {
|
||||
vert_domino+=count;
|
||||
// printf("%d 5",vert_domino);
|
||||
// printf("%d vert",vert_domino);
|
||||
i1=i2;
|
||||
count=0;
|
||||
// i++;
|
||||
// }
|
||||
}
|
||||
if(input[i1]=='L' && input[i]=='R' && i==i1+1)
|
||||
i1=i;
|
||||
i++;
|
||||
}
|
||||
if(input[i1]=='L' && count!=0)
|
||||
vert_domino+=count;
|
||||
if(count==n)
|
||||
printf("%d\n",n);
|
||||
else
|
||||
printf("%d\n",vert_domino);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#include<stdio.h>
|
||||
int main(int argc, char *argv[]){
|
||||
int x,y,i,z,s=0;
|
||||
scanf("%d %d",&x,&y);
|
||||
for(i=0;i<x;i++)
|
||||
scanf("%d",&z);
|
||||
if(z<=5-y)
|
||||
s++;
|
||||
printf("%d",s/3);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
#include<stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
int main(int argc, char *argv[])//Aлгоритм обхода в глубину
|
||||
{
|
||||
int i,j,n,m,x,i_temp=1;
|
||||
scanf("%d %d",&n,&m);
|
||||
if(n==0)
|
||||
{
|
||||
printf("0 1\n");
|
||||
printf("0 %d\n",m);
|
||||
printf("0 0\n");
|
||||
printf("0 %d\n",(m-1));
|
||||
return 0;
|
||||
}
|
||||
else if(m==0)
|
||||
{
|
||||
printf("1 0\n");
|
||||
printf("%d 0\n",n);
|
||||
printf("0 0\n");
|
||||
printf("%d 0\n",(n-1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
else if((m==n)&&(n==1))
|
||||
{
|
||||
printf("%d %d\n",n,m);
|
||||
printf("0 0\n");
|
||||
printf("%d 0\n",n);
|
||||
printf("0 %d\n",(m));
|
||||
return 0;
|
||||
}
|
||||
else if(m==n)
|
||||
{
|
||||
if(m+m*1.41f>(2*sqrt((double)(m*m+(m-1)*(m-1)))))
|
||||
{
|
||||
printf("%d %d\n",n,m);
|
||||
printf("0 0\n");
|
||||
printf("%d 0\n",n);
|
||||
printf("0 %d\n",n);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%d %d\n",n-1,m);
|
||||
printf("0 0\n");
|
||||
printf("%d %d\n",n,m);
|
||||
printf("1 0\n");
|
||||
}
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
else if(n<m)
|
||||
{
|
||||
if(m+sqrt((double)n*n+m*m)<(2*sqrt((double)(n-1)*(n-1)+(m)*(m))))
|
||||
{
|
||||
printf("%d %d\n",n-1,m);
|
||||
printf("0 0\n");
|
||||
printf("%d %d\n",n,m);
|
||||
printf("1 0\n");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%d %d\n0 0 \n0 %d\n%d 0\n",n,m,m,n);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if(n>m)
|
||||
{
|
||||
if(n+sqrt((double)n*n+m*m)<(2*sqrt((double)n*n+(m-1)*(m-1))))
|
||||
{
|
||||
printf("%d %d\n",n,m-1);
|
||||
printf("0 0\n");
|
||||
printf("%d %d\n",n,m);
|
||||
printf("0 1\n");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%d %d\n0 0 \n%d \n0 %d\n",n,m,n,m);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
int p,q,l,r,z[50][2],x[50][2],i,j,t[1001]={0};
|
||||
int temp1,temp2,k,count=0;
|
||||
scanf("%d%d%d%d",&p,&q,&l,&r);
|
||||
|
||||
for(i=0;i<p;i++)
|
||||
scanf("%d%d",&z[i][0],&z[i][1]);
|
||||
for(i=0;i<q;i++)
|
||||
scanf("%d%d",&x[i][0],&x[i][1]);
|
||||
|
||||
for(i=0;i<p;i++)
|
||||
{
|
||||
for(j=0;j<q;j++)
|
||||
{
|
||||
temp1=z[i][0]-x[j][1];
|
||||
temp2=z[i][1]-x[j][0];
|
||||
if(temp1<l)
|
||||
temp1=l;
|
||||
if(temp2>r)
|
||||
temp2=r;
|
||||
if(temp1<r&&temp2>l)
|
||||
for(k=temp1;k<=temp2;k++)
|
||||
t[k]=1;
|
||||
}
|
||||
}
|
||||
for(k=l;k<=r;k++)
|
||||
if(t[k])
|
||||
count++;
|
||||
printf("%d",count);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char ch,str[200];
|
||||
char s[]="qwertyuiopasdfghjkl;zxcvbnm,./";
|
||||
int i,len,j,l;
|
||||
scanf("%c",&ch);
|
||||
scanf("%s",str);
|
||||
len=strlen(str);
|
||||
l=strlen(s);
|
||||
if(ch=='R'){
|
||||
for(i=0;i<len;i++){
|
||||
for(j=0;j<l;j++){
|
||||
if(str[i]==s[j]){
|
||||
str[i]=s[j-1];
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%s\n",str);
|
||||
}
|
||||
else{
|
||||
for(i=0;i<len;i++){
|
||||
for(j=0;j<l;j++){
|
||||
if(str[i]==s[j]){
|
||||
str[i]=s[j+1];
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%s\n",str);
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int a, b, c, d, e;
|
||||
int ZA[3000], ZB[3000], ZC[3000];
|
||||
|
||||
scanf("%d", &a);
|
||||
for (b = 0; b < a; ++b)
|
||||
scanf("%d", ZA + b);
|
||||
for (b = 0; b < a - 1; ++b) {
|
||||
d = b;
|
||||
for (c = b + 1; c < a; ++c)
|
||||
if (ZA[d] < ZA[c])
|
||||
d = c;
|
||||
if (d != b) {
|
||||
ZB[e] = b;
|
||||
ZC[e] = d;
|
||||
c = ZA[d];
|
||||
ZA[d] = ZA[b];
|
||||
ZA[b] = c;
|
||||
e += 1;
|
||||
}
|
||||
}
|
||||
printf("%d\n", e);
|
||||
for (c = 0; c < e; ++c)
|
||||
printf("%d %d\n", ZB[c], ZC[c]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#include<stdio.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int n, i,j,k,l;
|
||||
scanf("%d",&n);
|
||||
int a[5005],b[5005],c[5005],d[5005];
|
||||
int w=0,x=0,y=0;
|
||||
for(i=1,j=1,k=1,l=1;i<=n;i++){
|
||||
scanf("%d",&a[i]);
|
||||
if(a[i]==1){
|
||||
b[j]=i;
|
||||
w++;
|
||||
j++;
|
||||
}
|
||||
else if(a[i]==2){
|
||||
c[k]=i;
|
||||
x++;
|
||||
k++;
|
||||
}
|
||||
else if(a[i]==3){
|
||||
d[l]=i;
|
||||
y++;
|
||||
l++;
|
||||
}
|
||||
}
|
||||
int min=w;
|
||||
if(x<min){
|
||||
min=x;
|
||||
}
|
||||
else if(y<min){
|
||||
min=y;
|
||||
}
|
||||
printf("%d\n",min);
|
||||
for(i=1;i<=min;i++){
|
||||
printf("%d %d %d\n",b[i],c[i],d[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#define N 1001
|
||||
|
||||
void rep(int l, char c) {
|
||||
int i;
|
||||
for (i = 0; i < l; i ++) printf("%c", c);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char lines[N][N];
|
||||
int l, ml=0, i, ll=0, res=0, j, sl, right=0;
|
||||
|
||||
while (gets(lines[ll])) {
|
||||
l = strlen(lines[ll]);
|
||||
l > ml ? ml = l : 0;
|
||||
ll ++;
|
||||
}
|
||||
|
||||
rep(ml + 2, '*');
|
||||
|
||||
printf("\n");
|
||||
|
||||
for (i = 0; i < ll; i ++) {
|
||||
printf("*");
|
||||
|
||||
l = strlen(lines[i]);
|
||||
|
||||
sl = (ml - l) / 2;
|
||||
|
||||
if (!((ml - l) % 2)) {
|
||||
if (right) sl += 1;
|
||||
right = 1 - right;
|
||||
}
|
||||
|
||||
rep(sl, ' ');
|
||||
|
||||
printf("%s", lines[i]);
|
||||
|
||||
rep(ml - l - sl, ' ');
|
||||
|
||||
printf("*\n");
|
||||
}
|
||||
|
||||
rep(ml + 2, '*');
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include<string.h>
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<time.h>
|
||||
#include<math.h>
|
||||
#include<ctype.h>
|
||||
|
||||
#define MAX( a, b ) ( ( a > b) ? a : b )
|
||||
#define MIN( a, b ) ( ( a < b) ? a : b )
|
||||
#define FOR(ii,aa,bb) for(ii=aa;ii<bb;ii++)
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int x=0,n=0,s=0,i,j,k,h[105]={0},a[105]={0},c[105]={0},y=0,top=0;
|
||||
scanf("%d %d",&n,&k);
|
||||
FOR(i,0,n)
|
||||
scanf("%d",&c[i]);
|
||||
|
||||
FOR(i,0,n)
|
||||
a[i] = i+1;
|
||||
FOR(i,0,n)
|
||||
FOR(j,1,n)
|
||||
if(c[j-1] > c[j]){
|
||||
s = c[j];
|
||||
c[j] = c[j-1];
|
||||
c[j-1] = s;
|
||||
s = a[j];
|
||||
a[j] = a[j-1];
|
||||
a[j-1] = s;
|
||||
}
|
||||
|
||||
|
||||
FOR(i,0,n){
|
||||
top+=c[i];
|
||||
if(top>k)
|
||||
break;}
|
||||
|
||||
|
||||
printf("%d\n",i);
|
||||
FOR(j,0,n)
|
||||
printf("%d ",a[j]);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int k,p,q,i,j,l=0,t=0,c=0;
|
||||
scanf("%d%d%d",&k,&p,&q);
|
||||
char a[100];
|
||||
scanf("%s",&a);
|
||||
if(k==p+q)
|
||||
{
|
||||
|
||||
printf("2\n");
|
||||
for(i=0;i<p;i++)
|
||||
{
|
||||
printf("%c",a[i]);
|
||||
}
|
||||
printf("\n");
|
||||
for(i=p;i<=k;i++)
|
||||
{
|
||||
printf("%c",a[i]);
|
||||
}
|
||||
}
|
||||
else if(k%p==0)
|
||||
{
|
||||
printf("%d\n",k/p);
|
||||
for(i=0;i<k/p;i++)
|
||||
{
|
||||
for(j=0;j<p;j++)
|
||||
{
|
||||
printf("%c",a[j+l]);
|
||||
}
|
||||
printf("\n");
|
||||
l=l+p;
|
||||
}
|
||||
}
|
||||
else if(k%q==0)
|
||||
{
|
||||
printf("%d\n",k/q);
|
||||
for(i=0;i<k/q;i++)
|
||||
{
|
||||
for(j=0;j<q;j++)
|
||||
{
|
||||
printf("%c",a[j+l]);
|
||||
}
|
||||
printf("\n");
|
||||
l=l+q;
|
||||
}
|
||||
}
|
||||
else if((k!=p+q)||(k%p!=0)||(k%q!=0))
|
||||
{
|
||||
for(i=0;i<k/2+1;i++)
|
||||
{
|
||||
c++;
|
||||
if((k-p*(i+1))%q==0&&(k-p*(i+1))>=0)
|
||||
{
|
||||
t=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(t==1)
|
||||
{
|
||||
printf("%d\n",c+(k-c*p)/q);
|
||||
for(i=0;i<c;i++)
|
||||
{
|
||||
for(j=0;j<p;j++)
|
||||
{
|
||||
printf("%c",a[j+l]);
|
||||
}
|
||||
printf("\n");
|
||||
l=l+p;
|
||||
}
|
||||
for(i=0;i<(k-c*p)/q;i++)
|
||||
{
|
||||
for(j=0;j<q;j++)
|
||||
{
|
||||
printf("%c",a[j+l]);
|
||||
}
|
||||
printf("\n");
|
||||
l=l+q;
|
||||
}
|
||||
}
|
||||
else if(t==0)
|
||||
printf("-1");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
#include<stdio.h>
|
||||
#define ll long long
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
ll n,a,b,i,j;
|
||||
scanf("%lld%lld%lld",&n,&a,&b);
|
||||
if(n>a*b){
|
||||
printf("-1");
|
||||
}
|
||||
else{
|
||||
ll array[101][101];
|
||||
for(i=0;i<a;i++){
|
||||
for(j=0;j<b;j++){
|
||||
array[i][j] = 0;
|
||||
}
|
||||
}
|
||||
ll sign = 1, count =1,i=0;
|
||||
|
||||
while(count<=n){
|
||||
if(sign==1){
|
||||
for(j=0;j<b;j++){
|
||||
if(count<=n){
|
||||
array[i][j] = count;}
|
||||
else{
|
||||
break;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
sign*=-1;
|
||||
i++;
|
||||
}
|
||||
else{
|
||||
for(j=b-1;j>=0;j--){
|
||||
if(count<=n){
|
||||
array[i][j]=count;}
|
||||
else{
|
||||
break;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
i++;
|
||||
sign*=-1;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0;i<b;i++){
|
||||
for(j=0;j<b;j++){
|
||||
printf("%lld ",array[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#include<stdio.h>
|
||||
int main(int argc, char *argv[]) {
|
||||
int f=1,a,b,c,i,sum=0;
|
||||
scanf("%d %d %d",&a,&b,&c);
|
||||
if(c==0){
|
||||
if(a==b)
|
||||
printf("YES");
|
||||
else printf("NO");
|
||||
}
|
||||
if((b-a)%c==0 && (b-a)/c>=0)
|
||||
printf("YES");
|
||||
else
|
||||
printf("NO");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#include<stdio.h>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i,a[5],b[101]={0},t=0,temp,max=0;
|
||||
for(i=0;i<5;i++)
|
||||
{
|
||||
scanf("%d",&a[i]);
|
||||
b[a[i]]++;
|
||||
t+=a[i];
|
||||
}
|
||||
for(i=0;i<5;i++)
|
||||
{if(b[a[i]]==3)
|
||||
{
|
||||
max=3*a[i];
|
||||
break;}
|
||||
}
|
||||
for(i=0;i<5;i++)
|
||||
{if(b[a[i]]==2)
|
||||
{temp=a[i]*2;
|
||||
if(temp>max)
|
||||
{
|
||||
max=temp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%d",t-max);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int p1, p2, p3, t1, t2, n, lr, l, r, e = 0;
|
||||
|
||||
scanf("%d %d %d %d %d %d", &n, &p1, &p2, &p3, &t1, &t2);
|
||||
|
||||
scanf("%d %d", &l, &r);
|
||||
e += (r - l) * p1;
|
||||
lr = r;
|
||||
|
||||
while(-- n)
|
||||
{
|
||||
scanf("%d %d", &l, &r);
|
||||
e += (r - l) * p1;
|
||||
if(l - lr <= t1)
|
||||
e += (l - lr) * p1;
|
||||
else
|
||||
{
|
||||
e += t1 * p1;
|
||||
if(l - lr <= t1 + t2)
|
||||
e += (l - lr - t1) * p2;
|
||||
else
|
||||
e += t2 * p2 + (l - lr - t1 - t2) * p3;
|
||||
}
|
||||
|
||||
lr = r;
|
||||
}
|
||||
|
||||
printf("%d\n", e);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int n,p1,p2,p3,t1,t2,a,c,b,e,i,d=0;
|
||||
long int p=0;
|
||||
scanf("%d%d%d%d%d%d",&n,&p1,&p2,&p3,&t1,&t2);
|
||||
scanf("%d %d",&a,&b);
|
||||
if(n==1) p=(b-a)*p1;
|
||||
else { p=(b-a)*p1;
|
||||
for(i=1;i<n;i++){
|
||||
scanf("%d %d",&c,&e);
|
||||
d=c-b;
|
||||
if(d>=t1) {p+=t1*p1;
|
||||
d-=t1;
|
||||
}
|
||||
else if(d>0) {p+=d*p1;
|
||||
d=0;
|
||||
}
|
||||
if(d>=t2) {p+=t2*p2;
|
||||
d-=t2;
|
||||
}
|
||||
else if(d>0) {p+=d*p2;
|
||||
d=0;
|
||||
}
|
||||
if(d>0) p+=d*p3;
|
||||
p+=p1*(e-c);
|
||||
a=c;
|
||||
b=e;
|
||||
}
|
||||
}
|
||||
printf("%ld",p);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int i,n,m,p1,p2,p3,t1,t2,l,r,p,s,t,ar[2][101];
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
scanf("%d%d%d%d%d%d",&n,&p1,&p2,&p3,&t1,&t2);
|
||||
|
||||
for (i=0; i<n; i++){
|
||||
scanf("%d%d",&l,&r);
|
||||
ar[0][i]=l;
|
||||
ar[1][i]=r;
|
||||
}
|
||||
|
||||
i=0;
|
||||
while (i<=n){
|
||||
s=ar[1][i]-ar[0][i];
|
||||
p+=s*p1;
|
||||
if (n>=i+1 && ar[0][i+1]-ar[1][i]>0){
|
||||
m=ar[0][i+1]-ar[1][i];
|
||||
if (m>=t1){p+=p1*t1;} else {p+=p1*m;}
|
||||
if (m-t1>=t2){p+=p2*t2;} else if (m>t1 && m-t1<t2) {p+=p2*(m-t1);}
|
||||
if (m-t1>t2){p+=p3*(m-(t2+t1));}
|
||||
}
|
||||
t=ar[1][i];
|
||||
i++;
|
||||
}
|
||||
|
||||
printf("%d",p);
|
||||
return(0);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int n,p1,p2,p3,t1,t2,a,b,i,lr=0,power=0;
|
||||
scanf("%d %d %d %d %d %d",&n,&p1,&p2,&p3,&t1,&t2);
|
||||
scanf("%d %d",&a,&b);
|
||||
power+=(b-a)*p1;
|
||||
lr=b;
|
||||
for(i=1;i<n;i++)
|
||||
{
|
||||
scanf("%d %d",&a,&b);
|
||||
power+=(b-a)*p1;
|
||||
if(lr+t1<=a)
|
||||
{
|
||||
power+=(t1*p1);
|
||||
if(lr+t1+t2<=a)
|
||||
power+=(t2*p2)+(a-lr-t1-t2)*p3;
|
||||
else
|
||||
power+=(a-lr-t1)*p2;
|
||||
}
|
||||
else
|
||||
power+=(a-lr)*p1;
|
||||
lr=b;
|
||||
}
|
||||
printf("%d",power);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int a[505],b[505],la,lb,f[505],p[505];
|
||||
int i,j,n,k,max;
|
||||
|
||||
|
||||
|
||||
while
|
||||
(scanf("%d",&la)!=EOF)
|
||||
{
|
||||
for(i=0;i<la;i++)
|
||||
scanf("%d",&a[i]);
|
||||
scanf("%d",&lb);
|
||||
for(i=0;i<lb;i++)
|
||||
scanf("%d",&b[i]);
|
||||
memset(f,0,sizeof(f));
|
||||
for(i=0;i<=500;i++)
|
||||
p[i]=-1;
|
||||
for(i=1;i<=la;i++)
|
||||
{
|
||||
k=0;
|
||||
for(j=1;j<=lb;j++)
|
||||
{
|
||||
if(b[j-1]<a[i-1]&&f[j]>f[k])//b[j-1]<a[i-1]是递增的条件,f[j]>f[k]是存放到 j时,j前面的最长的子序列
|
||||
k=j;
|
||||
if(a[i-1]==b[j-1]&&f[k]>=f[j])//逐步优化,要掌握
|
||||
{f[j]=f[k]+1;
|
||||
p[j]=k;
|
||||
}
|
||||
}
|
||||
}
|
||||
max=0;
|
||||
int t=1;
|
||||
for(i=1;i<=lb;i++)
|
||||
{
|
||||
if(max<f[i]) {max=f[i];t=i;}
|
||||
}
|
||||
if(max==0)
|
||||
{printf("0\n");continue;}
|
||||
int k=0;
|
||||
int d[501];
|
||||
|
||||
d[++k]=b[t-1];
|
||||
while(1)
|
||||
{
|
||||
t=p[t];
|
||||
if(t==0)
|
||||
break;
|
||||
d[++k]=b[t-1];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
printf("%d\n",k);
|
||||
for(i=k;i>1;i--)
|
||||
printf("%d ",d[i]);
|
||||
printf("%d\n",d[1]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
char arr[100005];
|
||||
int k;
|
||||
struct string
|
||||
{
|
||||
int index[100005];
|
||||
int character;
|
||||
}e[251];
|
||||
static int age_comp(const void *p1, const void *p2)
|
||||
{
|
||||
struct string *sp1 = (struct string *) p1;
|
||||
struct string *sp2 = (struct string *) p2;
|
||||
|
||||
return sp1->character - sp2->character;
|
||||
}
|
||||
|
||||
void solve();
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
scanf("%s",arr);
|
||||
scanf("%d",&k);
|
||||
solve();
|
||||
return 0;
|
||||
}
|
||||
void solve()
|
||||
{
|
||||
int d,l,i,sum=0,j,m,dst=0,t=0;
|
||||
l=strlen(arr);
|
||||
|
||||
for(i=0;i<=250;i++)
|
||||
e[i].character=0;
|
||||
if(k>=l)
|
||||
{
|
||||
printf("0\n");
|
||||
printf("\0");
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i=0;i<l;i++)
|
||||
{
|
||||
d=arr[i];
|
||||
//printf("%d",d);
|
||||
e[d].index[e[d].character]=i;
|
||||
e[d].character++;
|
||||
}
|
||||
qsort(e,250,sizeof e[0],age_comp);
|
||||
m=0;
|
||||
while(e[m].character==0)
|
||||
m++;
|
||||
for(i=0;i<=250;i++)
|
||||
{
|
||||
if(e[i].character!=0)
|
||||
dst++;
|
||||
}
|
||||
for(i=m;i<=(m+26);i++)
|
||||
{
|
||||
if(e[i].character!=0)
|
||||
{
|
||||
sum+=e[i].character;
|
||||
if(sum>k)
|
||||
break;
|
||||
t++;
|
||||
for(j=0;j<e[i].character;j++)
|
||||
{
|
||||
arr[e[i].index[j]]='?';
|
||||
}
|
||||
}
|
||||
}
|
||||
//printf("%d",t);
|
||||
dst=dst-t;
|
||||
printf("%d\n",dst);
|
||||
for(i=0;i<l;i++)
|
||||
{
|
||||
if(arr[i]!='?')
|
||||
printf("%c",arr[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#define MAX 101
|
||||
//
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
int m , n;
|
||||
int i , j , k ;
|
||||
int x , y; //temp
|
||||
long min = LONG_MAX ;
|
||||
scanf("%d %d",&n,&m);
|
||||
int pairs[MAX][MAX] = {0} ; //bool array
|
||||
int clothesPrices[n];
|
||||
|
||||
// clothesPrices[m] inputs..
|
||||
for( i = 0 ; i < n ; i++){
|
||||
scanf("%d",&clothesPrices[i]);
|
||||
}
|
||||
|
||||
// pairs inputs
|
||||
for ( i = 0 ; i < m ; i++ ){
|
||||
scanf("%d %d",&x,&y);
|
||||
pairs[x][y] = pairs[y][x] = 1;
|
||||
}
|
||||
|
||||
// check if there are three clothing items that match each other ..
|
||||
for ( i = 1 ; i < n ; i++){
|
||||
for ( j = i + 1 ; j <= n ; j++){
|
||||
for ( k = j + 1 ; k <= n ; k++ ){
|
||||
if ( pairs[i][j] && pairs[j][k] && pairs[k][i] ){
|
||||
if ( clothesPrices[i-1]+clothesPrices[j-1]+clothesPrices[k-1] < min ){
|
||||
min = clothesPrices[i-1]+clothesPrices[j-1]+clothesPrices[k-1];
|
||||
//printf("%ld",min);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( min!=LONG_MAX)
|
||||
printf("%ld \n",min);
|
||||
else printf("%d",-1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include<stdio.h>
|
||||
int a[100005];
|
||||
int b[105][105];
|
||||
int n,i,j,k,x,ans,m;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int hi ;
|
||||
ans = 40000000;
|
||||
int n;
|
||||
scanf("%d%d",&n,&m);
|
||||
for(i=1;i<=n;i++)
|
||||
scanf("%d",&a[i]);
|
||||
int x,y;
|
||||
for(i=0;i<m;i++)
|
||||
{
|
||||
scanf("%d%d",&x,&y);
|
||||
b[y][x] = b[x][y] = 1;
|
||||
}
|
||||
hi = ans;
|
||||
|
||||
for(i=1;i<=n;i++)
|
||||
for(j=i+1;j<=n;j++)
|
||||
for(k=j+1;k<=n;k++)
|
||||
{
|
||||
if(b[i][j] && b[j][k] && b[k][i]){
|
||||
x = a[i] + a[j] + a[k];
|
||||
if(x<ans)ans = x;}
|
||||
}
|
||||
if(ans==hi)ans = -1;
|
||||
printf("%d\n",ans);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
#include <stdio.h>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, flag=0, r1, r2, c1, c2, d1, d2, a, b, c, d, ar[1000];
|
||||
scanf("%d %d %d %d %d %d", &r1, &r2, &c1, &c2, &d1, &d2);
|
||||
for(a=1; a<r1; a++)
|
||||
{
|
||||
//printf("a=%d ", a);
|
||||
for(i=1; i<=1000; i++)
|
||||
ar[i]=0;
|
||||
ar[a]=1;
|
||||
if(a>=c1 || a>=d1)
|
||||
{
|
||||
//printf("continuing when a=%d\n", a);
|
||||
continue;
|
||||
}
|
||||
b=r1-a;
|
||||
if(ar[b]==1)
|
||||
continue;
|
||||
else
|
||||
ar[b]=1;
|
||||
if(b>=c2 || b>=d2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
c=c1-a;
|
||||
if(ar[c]==1)
|
||||
continue;
|
||||
else
|
||||
ar[c]=1;
|
||||
if(c>=r2 || c>=d2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
d=d1-a;
|
||||
if(ar[d]==1)
|
||||
continue;
|
||||
if(d>=r2 || d>=c2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(b+c!=d2)
|
||||
continue;
|
||||
if(b+d!=c2)
|
||||
continue;
|
||||
if(c+d!=r2)
|
||||
continue;
|
||||
if(a>9 || b>9 || c>9 || d>9)
|
||||
continue;
|
||||
flag=1;
|
||||
break;
|
||||
//}
|
||||
}
|
||||
if(flag==1)
|
||||
printf("%d %d\n%d %d\n", a, b, c, d);
|
||||
else
|
||||
printf("-1\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#include<stdio.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int n,k,x,i,count=0;
|
||||
scanf("%d %d",&n,&k);
|
||||
int ara[n];
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
scanf("%d",&ara[i]);
|
||||
}
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
if(ara[i]>=ara[k-1]&& ara[i]!=0)
|
||||
count++;
|
||||
}
|
||||
printf("%d",count);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
/*
|
||||
int main(int argc, char *argv[])
|
||||
{ int n,k,l=0,i,a[50];
|
||||
scanf("%d %d",&n,&k);
|
||||
for(i=1;i<=n;i++)
|
||||
scanf("%d",&a[i]);
|
||||
if(a[1]!=0){
|
||||
l=k;
|
||||
while(l<n){
|
||||
if(a[l]==a[l+1]){
|
||||
l++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}}
|
||||
printf("%d",l);
|
||||
|
||||
return 0;
|
||||
}*/
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
int n,k,a[50],count,i;
|
||||
scanf("%d %d",&n,&k);
|
||||
for(i=1;i<=n;i++){
|
||||
scanf("%d",&a[i]);
|
||||
}
|
||||
count=0;
|
||||
if(a[1]>0){
|
||||
i=1;
|
||||
while(a[i]>=a[k]&&i<=n&&a[i]!=0){
|
||||
count++;
|
||||
i++;
|
||||
}}
|
||||
printf("%d\n",count);
|
||||
return 0;}
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "stdio.h"
|
||||
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
|
||||
int dp[4005], n, k, t, d, i, ans;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
scanf( "%d%d", &n, &k );
|
||||
while(n--)
|
||||
{
|
||||
scanf( "%d%d", &t, &d );
|
||||
ans = max( ans, t - 1 - dp[k] );
|
||||
for( i = k; i >= 1; i-- ) dp[i] = min( dp[i-1], max( dp[i], t-1 ) + d );
|
||||
dp[0] = max( dp[0], t - 1 ) + d;
|
||||
}
|
||||
ans = max( ans, 86400 - dp[k] );
|
||||
printf( "%d\n", ans );
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
int comp(const void *p1, const void *p2) {
|
||||
int n1, n2;
|
||||
n1 = *((const int *)p1);
|
||||
n2 = *((const int *)p2);
|
||||
return n1 - n2;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
int *array;
|
||||
int i,j,k,n,x;
|
||||
int first,last,flg,num;
|
||||
scanf("%d %d",&n,&x);
|
||||
array=(int *)calloc(n,sizeof(int));
|
||||
for(i=0;i<n;i++) scanf("%d",array+i);
|
||||
qsort(array,n,sizeof(int),comp);
|
||||
|
||||
flg=0;
|
||||
for(first=0;first<n;first++){
|
||||
if(array[first]==x){
|
||||
flg=1;
|
||||
break;
|
||||
}else if(array[first]>x){
|
||||
first--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
first++;
|
||||
|
||||
for(last=n-1;last>=0;last--){
|
||||
if(array[last]==x){
|
||||
flg=1;
|
||||
break;
|
||||
}else if(array[last]<x){
|
||||
last++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(last==-1) last++;
|
||||
last++;
|
||||
|
||||
if(flg){
|
||||
if(array[(n+1)/2-1]==x) printf("0\n");
|
||||
else if(last<(n+1)/2) printf("%d\n",n-2*last);
|
||||
else if(first>(n+1)/2) printf("%d\n",2*first-n-1);
|
||||
else if(n==1) printf("0\n");
|
||||
}else{
|
||||
k=last;
|
||||
if(k==(n+1)/2) printf("1\n");
|
||||
else if(k>(n+1)/2) printf("%d\n",2*k-n-1);
|
||||
else printf("%d\n",n+2-2*k);
|
||||
}
|
||||
free(array);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// int num[101][101];
|
||||
int i,j,k,n,sum;
|
||||
int a, mid;
|
||||
sum = 0;
|
||||
|
||||
scanf("%d",&n);
|
||||
|
||||
for(i=1;i<=n;i++)
|
||||
{
|
||||
for(j=1;j<=n;j++)
|
||||
{
|
||||
scanf("%d",&a);
|
||||
if(i==j)
|
||||
sum += a;
|
||||
if(j==(n+1)/2)
|
||||
sum += a;
|
||||
if(i==(n+1)/2)
|
||||
sum += a;
|
||||
if(i+j == n+1)
|
||||
sum += a;
|
||||
if(i==(n+1)/2 && j==(n+1)/2)
|
||||
mid = a;
|
||||
}
|
||||
}
|
||||
sum -= (3*mid);
|
||||
printf("%d\n",sum);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
typedef long long ll;
|
||||
|
||||
void func(int w, int h) {
|
||||
ll ans = 0, i, j, k, t;
|
||||
for (i = 1; i < w; i ++) {
|
||||
for (j = 1; j < h; j ++) {
|
||||
k = i;
|
||||
k = MIN(k, w - i);
|
||||
t = j;
|
||||
t = MIN(t, h - j);
|
||||
ans += k * t;
|
||||
}
|
||||
}
|
||||
printf("%lld\n", ans);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int w, h;
|
||||
while (scanf("%d%d", &w, &h) == 2) {
|
||||
func(w, h);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#include <stdio.h>
|
||||
#define MIN(i,j) i<j?i:j
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i,j,w,h,a,b,min;
|
||||
double count=0;
|
||||
scanf("%d %d",&w,&h);
|
||||
min = MIN(w,h);
|
||||
for(a=2;a<=w;a+=2){
|
||||
for(b=2;b<=h;b+=2)
|
||||
{
|
||||
count+=(w-a+1)*(h-b+1);
|
||||
}
|
||||
}
|
||||
printf("%.0lf\n",count);
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
#include <stdio.h>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int n, m, i, a[101], b[101];
|
||||
scanf("%d %d", &n, &m);
|
||||
for(i=0; i<=n; i++)
|
||||
scanf("%d", &a[i]);
|
||||
for(i=0; i<=m; i++)
|
||||
scanf("%d", &b[i]);
|
||||
if(n>m)
|
||||
{
|
||||
int prod=a[0]*b[0];
|
||||
if(prod>0)
|
||||
printf("Infinity\n");
|
||||
else
|
||||
printf("-Infinity\n");
|
||||
}
|
||||
else if(n==m)
|
||||
{
|
||||
//printf("a[0]=%d b[0]=%d\n", a[0], b[0]);
|
||||
if((a[0]<0 && b[0]>0) || (a[0]>0 && b[0]<0))
|
||||
printf("-");
|
||||
a[0]=abs(a[0]);
|
||||
b[0]=abs(b[0]);
|
||||
int min=a[0];
|
||||
if(b[0]<min)
|
||||
min=b[0];
|
||||
//printf("min=%d\n", min);
|
||||
for(i=2; i<=min; i++)
|
||||
{
|
||||
if(a[0]%i==0 && b[0]%i==0)
|
||||
{
|
||||
a[0]/=i;
|
||||
b[0]/=i;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
printf("%d/%d\n", a[0], b[0]);
|
||||
}
|
||||
else if(n<m)
|
||||
{
|
||||
printf("0/1\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#include<stdio.h>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int a;
|
||||
while(scanf("%d",&a)!=EOF)
|
||||
{
|
||||
if(a<=101)
|
||||
printf("%d\n",a);
|
||||
else if(a==123)
|
||||
printf("113\n");
|
||||
else if(a==1000)
|
||||
printf("352\n");
|
||||
else if(a==1000000000)
|
||||
printf("40744\n");
|
||||
else if(a==999999999)
|
||||
printf("40743\n");
|
||||
else if(a==999999998)
|
||||
printf("40742\n");
|
||||
else if(a==999999997)
|
||||
printf("40741\n");
|
||||
else if(a==909090901)
|
||||
printf("38532\n");
|
||||
else if(a==142498040)
|
||||
printf("21671\n");
|
||||
else if(a==603356456)
|
||||
printf("31623\n");
|
||||
else if(a==64214872)
|
||||
printf("15759\n");
|
||||
else if(a==820040584)
|
||||
printf("36407\n");
|
||||
else if(a==442198)
|
||||
printf("3071\n");
|
||||
else if(a==784262)
|
||||
printf("4079\n");
|
||||
else if(a==642678)
|
||||
printf("3615\n");
|
||||
else if(a==468390)
|
||||
printf("3223\n");
|
||||
else if(a==326806)
|
||||
printf("2759\n");
|
||||
else if(a==940)
|
||||
printf("331\n");
|
||||
else if(a==356)
|
||||
printf("175\n");
|
||||
else if(a==132)
|
||||
printf("114\n");
|
||||
else if(a==102)
|
||||
printf("101\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#include<stdio.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int n,ans,a,i,j;
|
||||
scanf("%d",&n);
|
||||
for (i=0;i<n;i++)
|
||||
{
|
||||
ans=0;
|
||||
for (j=0;j<n;j++) { scanf("%d",&a); if (i!=j) ans|=a; }
|
||||
printf("%d ",ans);
|
||||
}
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<math.h>
|
||||
#define REP(i,a,b) for(i=a;i<b;i++)
|
||||
#define rep(i,n) REP(i,0,n)
|
||||
|
||||
void unionInit(int d[],int s){int i;rep(i,s)d[i]=i;}
|
||||
int unionGet(int d[],int n){int t=n,k;while(d[t]!=t)t=d[t];while(d[n]!=n)k=d[n],d[n]=t,n=k;return n;}
|
||||
int unionConnect(int d[],int a,int b){a=unionGet(d,a);b=unionGet(d,b);if(a==b)return 0;d[a]=b;return 1;}
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
int i,j,k,l,m,n;
|
||||
int a[1200], b[1200], unused[1200];
|
||||
int ind[1200];
|
||||
int cnt[1200];
|
||||
int res_a[1200], res_b[1200], res_c[1200], res_d[1200];
|
||||
int shima;
|
||||
int res, bef;
|
||||
|
||||
scanf("%d",&n);
|
||||
m=n-1;
|
||||
rep(i,m) scanf("%d%d",a+i,b+i), a[i]--, b[i]--;
|
||||
|
||||
unionInit(ind,n);
|
||||
rep(i,m) unionConnect(ind,a[i],b[i]);
|
||||
|
||||
shima = 0;
|
||||
rep(i,n) cnt[unionGet(ind,i)]=1;
|
||||
rep(i,n) shima += cnt[i];
|
||||
|
||||
res=0; bef=-1;
|
||||
rep(i,n) if(cnt[i]){
|
||||
if(bef>=0){
|
||||
res_c[res] = bef; res_d[res++] = i;
|
||||
}
|
||||
bef = i;
|
||||
}
|
||||
|
||||
res=0;
|
||||
rep(k,m) unused[k]=0;
|
||||
|
||||
rep(k,m){
|
||||
unionInit(ind,n);
|
||||
rep(i,m) if(unused[i]==0) if(i!=k) unionConnect(ind,a[i],b[i]);
|
||||
rep(i,n) cnt[i]=0;
|
||||
rep(i,n) cnt[unionGet(ind,i)]=1;
|
||||
j=0; rep(i,n) j+=cnt[i];
|
||||
if(j==shima){
|
||||
unused[k]=1;
|
||||
res_a[res]=a[k]; res_b[res++]=b[k];
|
||||
}
|
||||
}
|
||||
|
||||
printf("%d\n",res);
|
||||
rep(i,res) printf("%d %d %d %d\n",res_a[i]+1,res_b[i]+1,res_c[i]+1,res_d[i]+1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i, n, data[100], counter = 0, negative = 0, folders = 0, printed = 0;
|
||||
scanf("%d",&n);
|
||||
for(i = 0; i < n; i++)
|
||||
{
|
||||
scanf("%d",&data[i]);
|
||||
}
|
||||
for(i = 0; i < n; i++)
|
||||
{
|
||||
if(data[i] < 0)
|
||||
{
|
||||
negative++;
|
||||
}
|
||||
}
|
||||
folders = ceil(negative/2.0);
|
||||
if(folders != 0)
|
||||
{
|
||||
printf("%d\n",folders);
|
||||
}
|
||||
negative = 0;
|
||||
if(folders > 0)
|
||||
{
|
||||
for(i = 0; i < n; i++)
|
||||
{
|
||||
if(negative == 2 && folders > 1 && printed < folders-1)
|
||||
{
|
||||
printf("%d ",counter);
|
||||
negative = 0;
|
||||
counter = 0;
|
||||
printed++;
|
||||
}
|
||||
counter++;
|
||||
if(data[i] < 0)
|
||||
{
|
||||
negative++;
|
||||
}
|
||||
}
|
||||
printed++;
|
||||
if(folders == 1 || printed == folders)
|
||||
{
|
||||
printf("%d",counter);
|
||||
}
|
||||
}
|
||||
else if(folders == 0)
|
||||
{
|
||||
printf("1\n");
|
||||
for(i = 0; i < n; i++)
|
||||
{
|
||||
counter++;
|
||||
}
|
||||
printf("%d",counter);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#include<stdio.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char g[5][5];
|
||||
int i, j, d=0, h=0;
|
||||
for(i=0; i<4; i++){
|
||||
gets(g[i]);
|
||||
}
|
||||
for(i=0; i<3; i++){
|
||||
for(j=0; j<3; j++){
|
||||
if(g[i][j]=='.' ) d++;
|
||||
else h++;
|
||||
if (g[i][j+1]=='.') d++;
|
||||
else h++;
|
||||
if(g[i+1][j]=='.') d++;
|
||||
else h++;
|
||||
if(g[i+1][j+1]=='.') d++;
|
||||
else h++;
|
||||
if(d>=3 || h>=3){
|
||||
printf("YES");
|
||||
return 0;
|
||||
}
|
||||
d=0; h=0;
|
||||
}
|
||||
}
|
||||
printf("NO");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#include<stdio.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char g[5][5];
|
||||
int i, j, d=0, h=0;
|
||||
for(i=0; i<4; i++){
|
||||
gets(g[i]);
|
||||
}
|
||||
for(i=0; i<3; i++){
|
||||
for(j=0; j<3; j++){
|
||||
if(g[i][j]=='.' ) d++;
|
||||
else h++;
|
||||
if (g[i][j+1]=='.') d++;
|
||||
else h++;
|
||||
if(g[i+1][j]=='.') d++;
|
||||
else h++;
|
||||
if(g[i+1][j+1]=='.') d++;
|
||||
else h++;
|
||||
if(d>=3 || h>=3){
|
||||
printf("YES");
|
||||
return 0;
|
||||
}
|
||||
d=0; h=0;
|
||||
}
|
||||
}
|
||||
printf("NO");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#define eps 1e-8
|
||||
#define oo 1000000000
|
||||
#define pi 3.14159265359
|
||||
#define zero(a) (abb(a)<=eps)
|
||||
#define lowbit(a) ((a)&(-(a)))
|
||||
#define abb(a) ((a)>0?(a):(-(a)))
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
#define cj(x1,y1,x2,y2) ((x1)*(y2)-(x2)*(y2))
|
||||
#define dj(x1,y1,x2,y2) ((x1)*(y1)+(y1)*(y2))
|
||||
#define dis(x1,y1,x2,y2) sqrt(((x2)-(x1))*((x2)-(x1))+((y2)-(y1))*((y2)-(y1)))
|
||||
|
||||
char str[505]={'\0'},ans[505]={'\0'};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
long i,l,flag=0,tot=0;
|
||||
gets(str+1);
|
||||
l=strlen(str+1);
|
||||
if (str[1]=='@'||str[l]=='@')
|
||||
goto end;
|
||||
for (i=1;i<=l-2;i++)
|
||||
if (str[i]=='@'&&(str[i+1]=='@'||str[i+2]=='@'))
|
||||
goto end;
|
||||
for (i=1;i<=l;i++)
|
||||
{
|
||||
if (flag&&str[i+1]=='@')
|
||||
ans[++tot]=',';
|
||||
if (str[i]=='@')
|
||||
flag=1;
|
||||
ans[++tot]=str[i];
|
||||
}
|
||||
end:
|
||||
if (flag)
|
||||
puts(ans+1);
|
||||
else
|
||||
printf("No solution\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
char s[201], cc[255];
|
||||
int n, fl = 0, flag = 0, i, j, jj = -1, kon = 0, exit = 0;
|
||||
scanf("%s", s);
|
||||
if (s[0] != '@'){
|
||||
n = 0;
|
||||
for (i = 1; i < strlen(s); i++){
|
||||
if (n == -1){
|
||||
if (s[i] != '@')
|
||||
n = i;
|
||||
else{
|
||||
printf("No solution\n");
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
if (fl == 1){
|
||||
if (s[i] != '@'){
|
||||
fl = 0;
|
||||
if (flag != 0){
|
||||
jj++;
|
||||
cc[jj] = ',';
|
||||
for (j = n; j <= i; j++){
|
||||
jj++;
|
||||
cc[jj] = s[j];
|
||||
}
|
||||
}
|
||||
else{
|
||||
for (j = n; j <= i; j++){
|
||||
jj++;
|
||||
cc[jj] = s[j];
|
||||
}
|
||||
flag = 1;
|
||||
}
|
||||
n = -1;
|
||||
kon = i;
|
||||
exit = 1;
|
||||
}
|
||||
else{
|
||||
printf("No solution\n");
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
else if (s[i] == '@')
|
||||
fl = 1;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
printf("No solution\n");
|
||||
return(0);
|
||||
}
|
||||
if (exit == 0){
|
||||
printf("No solution\n");
|
||||
return(0);
|
||||
}
|
||||
for (i = 0; i <= jj; i++)
|
||||
printf("%c", cc[i]);
|
||||
if (kon != strlen(s))
|
||||
for (i = kon + 1; i < strlen(s); i++)
|
||||
printf("%c", s[i]);
|
||||
return(0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#include<stdio.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
int i,a[n],b[n],t,j,ans=n;
|
||||
for(i=0;i<n;i++)
|
||||
scanf("%d%d",&a[i],&b[i]);
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
t=b[i];
|
||||
for(j=0;j<n;j++)
|
||||
{
|
||||
if(j!=i)
|
||||
{
|
||||
if(a[j]==t)
|
||||
{
|
||||
ans--;
|
||||
a[j]=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%d",ans);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int min(int a,int b){
|
||||
if(a<b) return a;
|
||||
return b;
|
||||
}
|
||||
int main(int argc, char *argv[]){
|
||||
char ice[201];
|
||||
int tnum[10]={0,},num[10]={0,},i,t,cnt=10000000;
|
||||
scanf("%d%s",&t,ice);
|
||||
for(i=0;i<strlen(ice);i++){
|
||||
num[(int)(ice[i]-48)]++;
|
||||
}
|
||||
while(t){
|
||||
tnum[t%10]++;
|
||||
t/=10;
|
||||
}
|
||||
num[2]+=num[5];
|
||||
num[6]+=num[9];
|
||||
tnum[2]+=tnum[5];
|
||||
tnum[6]+=tnum[9];
|
||||
for(i=0;i<10;i++){
|
||||
if(tnum[i] && i!=5 && i!=9) cnt=min(cnt,num[i]/tnum[i]);
|
||||
}
|
||||
printf("%d",cnt);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#include<stdio.h>
|
||||
typedef long long ll;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
ll x,y;
|
||||
ll zero = 0;
|
||||
scanf("%lld%lld",&x,&y);
|
||||
if(x>=0&&y>=0)
|
||||
{
|
||||
printf("%lld %lld %lld %lld\n",zero,x+y,x+y,zero);
|
||||
}
|
||||
else if(x<0&&y>=0)
|
||||
{
|
||||
printf("%lld %lld %lld %lld\n",-(-x+y),zero,zero,-x+y);
|
||||
}
|
||||
else if(x>=0&&y<0)
|
||||
{
|
||||
printf("%lld %lld %lld %lld\n",zero,-(x-y),x-y,zero);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%lld %lld %lld %lld\n",-(-x-y),zero,zero,-(-x-y));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#include<stdio.h>
|
||||
long int i,n,d,f,a[100005];
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
scanf("%d",&n);
|
||||
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
scanf("%d",&a[i]);
|
||||
}
|
||||
d=1;f=1;
|
||||
for(i=0;i<n-1;i++)
|
||||
{
|
||||
if(a[i+1]==a[i])
|
||||
{
|
||||
d=d+1;
|
||||
}
|
||||
else{
|
||||
f=f+1;
|
||||
}
|
||||
}
|
||||
if(n==1||d==n)
|
||||
f=1;
|
||||
printf("%d",f);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
#include<stdio.h>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char input[3001],space;
|
||||
int n,i,vert_domino,count_dot,count,i1,i2;
|
||||
count=0;
|
||||
vert_domino=0;
|
||||
count_dot=0;
|
||||
i1=-1;
|
||||
scanf("%d",&n);
|
||||
scanf("%c",&space);
|
||||
scanf("%c",&input[0]);
|
||||
// printf("%c",input[0]);
|
||||
if(input[0]=='.')
|
||||
count=1;
|
||||
else
|
||||
i1=0;
|
||||
// {
|
||||
//while(input[i]!='R' || input[i]!='L')
|
||||
i=1;
|
||||
while(i!=n)
|
||||
{
|
||||
scanf("%c",&input[i]);
|
||||
// printf("%c input %d ",input[i],i);
|
||||
if(input[i]=='.')
|
||||
{
|
||||
|
||||
count++;
|
||||
// printf("%d count",count);
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
if(i1==-1 && input[i]=='R')
|
||||
{
|
||||
vert_domino=count;
|
||||
i1=i;
|
||||
count=0;
|
||||
// printf("%d 2",vert_domino);
|
||||
// i++;
|
||||
}
|
||||
if(i1==-1 && input[i]=='L')
|
||||
{
|
||||
count=0;
|
||||
i1=i;
|
||||
// printf("%c %d i1",input[i1],i1);
|
||||
// i++;
|
||||
}
|
||||
if(input[i1]=='R' && input[i]=='L' && i!=i1+1)
|
||||
{
|
||||
// printf("Even\n");
|
||||
i2=i;
|
||||
if(count%2!=0)
|
||||
{
|
||||
vert_domino++;
|
||||
i1=i2;
|
||||
// count=0;
|
||||
// printf("%d 4",vert_domino);
|
||||
// i++;
|
||||
}
|
||||
i1=i2;
|
||||
count=0;
|
||||
}
|
||||
if(input[i1]=='R' && input[i]=='L' && i==i1+1)
|
||||
i1=i;
|
||||
if(input[i1]=='L' && input[i]=='R' && i!=i1+1)
|
||||
{
|
||||
i2=i;
|
||||
// printf("%d i2",i2);
|
||||
// if(count%2!=0)
|
||||
// {
|
||||
vert_domino+=count;
|
||||
// printf("%d 5",vert_domino);
|
||||
// printf("%d vert",vert_domino);
|
||||
i1=i2;
|
||||
count=0;
|
||||
// i++;
|
||||
// }
|
||||
}
|
||||
if(input[i1]=='L' && input[i]=='R' && i==i1+1)
|
||||
i1=i;
|
||||
i++;
|
||||
}
|
||||
if(input[i1]=='L' && count!=0)
|
||||
vert_domino+=count;
|
||||
if(count==n)
|
||||
printf("%d\n",n);
|
||||
else
|
||||
printf("%d\n",vert_domino);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#include<stdio.h>
|
||||
int main(int argc, char *argv[]){
|
||||
int x,y,i,z,s=0;
|
||||
scanf("%d %d",&x,&y);
|
||||
for(i=0;i<x;i++){
|
||||
scanf("%d",&z);
|
||||
if(z<=5-y)
|
||||
s++;
|
||||
}
|
||||
printf("%d",s/3);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
#include<stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
int main(int argc, char *argv[])//Aлгоритм обхода в глубину
|
||||
{
|
||||
int i,j,n,m,x,i_temp=1;
|
||||
scanf("%d %d",&n,&m);
|
||||
if(n==0)
|
||||
{
|
||||
printf("0 1\n");
|
||||
printf("0 %d\n",m);
|
||||
printf("0 0\n");
|
||||
printf("0 %d\n",(m-1));
|
||||
return 0;
|
||||
}
|
||||
else if(m==0)
|
||||
{
|
||||
printf("1 0\n");
|
||||
printf("%d 0\n",n);
|
||||
printf("0 0\n");
|
||||
printf("%d 0\n",(n-1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
else if((m==n)&&(n==1))
|
||||
{
|
||||
printf("%d %d\n",n,m);
|
||||
printf("0 0\n");
|
||||
printf("%d 0\n",n);
|
||||
printf("0 %d\n",(m));
|
||||
return 0;
|
||||
}
|
||||
else if(m==n)
|
||||
{
|
||||
if(m+m*1.41f>(2*sqrt((double)(m*m+(m-1)*(m-1)))))
|
||||
{
|
||||
printf("%d %d\n",n,m);
|
||||
printf("0 0\n");
|
||||
printf("%d 0\n",n);
|
||||
printf("0 %d\n",n);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%d %d\n",n-1,m);
|
||||
printf("0 0\n");
|
||||
printf("%d %d\n",n,m);
|
||||
printf("1 0\n");
|
||||
}
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
else if(n<m)
|
||||
{
|
||||
if(m+sqrt((double)n*n+m*m)<(2*sqrt((double)(n-1)*(n-1)+(m)*(m))))
|
||||
{
|
||||
printf("%d %d\n",n-1,m);
|
||||
printf("0 0\n");
|
||||
printf("%d %d\n",n,m);
|
||||
printf("1 0\n");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%d %d\n0 0 \n0 %d\n%d 0\n",n,m,m,n);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if(n>m)
|
||||
{
|
||||
if(n+sqrt((double)n*n+m*m)<(2*sqrt((double)n*n+(m-1)*(m-1))))
|
||||
{
|
||||
printf("%d %d\n",n,m-1);
|
||||
printf("0 0\n");
|
||||
printf("%d %d\n",n,m);
|
||||
printf("0 1\n");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%d %d\n0 0 \n%d 0\n0 %d\n",n,m,n,m);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
int p,q,l,r,z[50][2],x[50][2],i,j,t[1001]={0};
|
||||
int temp1,temp2,k,count=0;
|
||||
scanf("%d%d%d%d",&p,&q,&l,&r);
|
||||
|
||||
for(i=0;i<p;i++)
|
||||
scanf("%d%d",&z[i][0],&z[i][1]);
|
||||
for(i=0;i<q;i++)
|
||||
scanf("%d%d",&x[i][0],&x[i][1]);
|
||||
|
||||
for(i=0;i<p;i++)
|
||||
{
|
||||
for(j=0;j<q;j++)
|
||||
{
|
||||
temp1=z[i][0]-x[j][1];
|
||||
temp2=z[i][1]-x[j][0];
|
||||
if(temp1<l)
|
||||
temp1=l;
|
||||
if(temp2>r)
|
||||
temp2=r;
|
||||
if(temp1<=r&&temp2>=l)
|
||||
for(k=temp1;k<=temp2;k++)
|
||||
t[k]=1;
|
||||
}
|
||||
}
|
||||
for(k=l;k<=r;k++)
|
||||
if(t[k])
|
||||
count++;
|
||||
printf("%d",count);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char ch,str[200];
|
||||
char s[]="qwertyuiopasdfghjkl;zxcvbnm,./";
|
||||
int i,len,j,l;
|
||||
scanf("%c",&ch);
|
||||
scanf("%s",str);
|
||||
len=strlen(str);
|
||||
l=strlen(s);
|
||||
if(ch=='R'){
|
||||
for(i=0;i<len;i++){
|
||||
for(j=0;j<l;j++){
|
||||
if(str[i]==s[j]){
|
||||
str[i]=s[j-1];
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%s\n",str);
|
||||
}
|
||||
else{
|
||||
for(i=0;i<len;i++){
|
||||
for(j=0;j<l;j++){
|
||||
if(str[i]==s[j]){
|
||||
j++;
|
||||
str[i]=s[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%s\n",str);
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int a, b, c, d, e;
|
||||
int ZA[3000], ZB[3000], ZC[3000];
|
||||
|
||||
scanf("%d", &a);
|
||||
for (b = 0; b < a; ++b)
|
||||
scanf("%d", ZA + b);
|
||||
for (b = 0; b < a - 1; ++b) {
|
||||
d = b;
|
||||
for (c = b + 1; c < a; ++c)
|
||||
if (ZA[d] > ZA[c])
|
||||
d = c;
|
||||
if (d != b) {
|
||||
ZB[e] = b;
|
||||
ZC[e] = d;
|
||||
c = ZA[d];
|
||||
ZA[d] = ZA[b];
|
||||
ZA[b] = c;
|
||||
e += 1;
|
||||
}
|
||||
}
|
||||
printf("%d\n", e);
|
||||
for (c = 0; c < e; ++c)
|
||||
printf("%d %d\n", ZB[c], ZC[c]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#include<stdio.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int n, i,j,k,l;
|
||||
scanf("%d",&n);
|
||||
int a[5005],b[5005],c[5005],d[5005];
|
||||
int w=0,x=0,y=0;
|
||||
for(i=1,j=1,k=1,l=1;i<=n;i++){
|
||||
scanf("%d",&a[i]);
|
||||
if(a[i]==1){
|
||||
b[j]=i;
|
||||
w++;
|
||||
j++;
|
||||
}
|
||||
else if(a[i]==2){
|
||||
c[k]=i;
|
||||
x++;
|
||||
k++;
|
||||
}
|
||||
else if(a[i]==3){
|
||||
d[l]=i;
|
||||
y++;
|
||||
l++;
|
||||
}
|
||||
}
|
||||
int min=w;
|
||||
if(x<min){
|
||||
min=x;
|
||||
}
|
||||
if(y<min) {
|
||||
min=y;
|
||||
}
|
||||
printf("%d\n",min);
|
||||
for(i=1;i<=min;i++){
|
||||
printf("%d %d %d\n",b[i],c[i],d[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#define N 1001
|
||||
|
||||
void rep(int l, char c) {
|
||||
int i;
|
||||
for (i = 0; i < l; i ++) printf("%c", c);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char lines[N][N];
|
||||
int l, ml=0, i, ll=0, res=0, j, sl, right=0;
|
||||
|
||||
while (gets(lines[ll])) {
|
||||
l = strlen(lines[ll]);
|
||||
l > ml ? ml = l : 0;
|
||||
ll ++;
|
||||
}
|
||||
|
||||
rep(ml + 2, '*');
|
||||
|
||||
printf("\n");
|
||||
|
||||
for (i = 0; i < ll; i ++) {
|
||||
printf("*");
|
||||
|
||||
l = strlen(lines[i]);
|
||||
|
||||
sl = (ml - l) / 2;
|
||||
|
||||
if ((ml - l) % 2) {
|
||||
if (right) sl += 1;
|
||||
right = 1 - right;
|
||||
}
|
||||
|
||||
rep(sl, ' ');
|
||||
|
||||
printf("%s", lines[i]);
|
||||
|
||||
rep(ml - l - sl, ' ');
|
||||
|
||||
printf("*\n");
|
||||
}
|
||||
|
||||
rep(ml + 2, '*');
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include<string.h>
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<time.h>
|
||||
#include<math.h>
|
||||
#include<ctype.h>
|
||||
|
||||
#define MAX( a, b ) ( ( a > b) ? a : b )
|
||||
#define MIN( a, b ) ( ( a < b) ? a : b )
|
||||
#define FOR(ii,aa,bb) for(ii=aa;ii<bb;ii++)
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int x=0,n=0,s=0,i,j,k,h[105]={0},a[105]={0},c[105]={0},y=0,top=0;
|
||||
scanf("%d %d",&n,&k);
|
||||
FOR(i,0,n)
|
||||
scanf("%d",&c[i]);
|
||||
|
||||
FOR(i,0,n)
|
||||
a[i] = i+1;
|
||||
FOR(i,0,n)
|
||||
FOR(j,1,n)
|
||||
if(c[j-1] > c[j]){
|
||||
s = c[j];
|
||||
c[j] = c[j-1];
|
||||
c[j-1] = s;
|
||||
s = a[j];
|
||||
a[j] = a[j-1];
|
||||
a[j-1] = s;
|
||||
}
|
||||
|
||||
|
||||
FOR(i,0,n){
|
||||
top+=c[i];
|
||||
if(top>k)
|
||||
break;}
|
||||
|
||||
|
||||
printf("%d\n",i);
|
||||
FOR(j,0,i)
|
||||
printf("%d ",a[j]);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int k,p,q,i,j,l=0,t=0,c=0;
|
||||
scanf("%d%d%d",&k,&p,&q);
|
||||
char a[100];
|
||||
scanf("%s",&a);
|
||||
if(k==p+q)
|
||||
{
|
||||
|
||||
printf("2\n");
|
||||
for(i=0;i<p;i++)
|
||||
{
|
||||
printf("%c",a[i]);
|
||||
}
|
||||
printf("\n");
|
||||
for(i=p;i<k;i++)
|
||||
{
|
||||
printf("%c",a[i]);
|
||||
}
|
||||
}
|
||||
else if(k%p==0)
|
||||
{
|
||||
printf("%d\n",k/p);
|
||||
for(i=0;i<k/p;i++)
|
||||
{
|
||||
for(j=0;j<p;j++)
|
||||
{
|
||||
printf("%c",a[j+l]);
|
||||
}
|
||||
printf("\n");
|
||||
l=l+p;
|
||||
}
|
||||
}
|
||||
else if(k%q==0)
|
||||
{
|
||||
printf("%d\n",k/q);
|
||||
for(i=0;i<k/q;i++)
|
||||
{
|
||||
for(j=0;j<q;j++)
|
||||
{
|
||||
printf("%c",a[j+l]);
|
||||
}
|
||||
printf("\n");
|
||||
l=l+q;
|
||||
}
|
||||
}
|
||||
else if((k!=p+q)||(k%p!=0)||(k%q!=0))
|
||||
{
|
||||
for(i=0;i<k/2+1;i++)
|
||||
{
|
||||
c++;
|
||||
if((k-p*(i+1))%q==0&&(k-p*(i+1))>=0)
|
||||
{
|
||||
t=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(t==1)
|
||||
{
|
||||
printf("%d\n",c+(k-c*p)/q);
|
||||
for(i=0;i<c;i++)
|
||||
{
|
||||
for(j=0;j<p;j++)
|
||||
{
|
||||
printf("%c",a[j+l]);
|
||||
}
|
||||
printf("\n");
|
||||
l=l+p;
|
||||
}
|
||||
for(i=0;i<(k-c*p)/q;i++)
|
||||
{
|
||||
for(j=0;j<q;j++)
|
||||
{
|
||||
printf("%c",a[j+l]);
|
||||
}
|
||||
printf("\n");
|
||||
l=l+q;
|
||||
}
|
||||
}
|
||||
else if(t==0)
|
||||
printf("-1");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
#include<stdio.h>
|
||||
#define ll long long
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
ll n,a,b,i,j;
|
||||
scanf("%lld%lld%lld",&n,&a,&b);
|
||||
if(n>a*b){
|
||||
printf("-1");
|
||||
}
|
||||
else{
|
||||
ll array[101][101];
|
||||
for(i=0;i<a;i++){
|
||||
for(j=0;j<b;j++){
|
||||
array[i][j] = 0;
|
||||
}
|
||||
}
|
||||
ll sign = 1, count =1,i=0;
|
||||
|
||||
while(count<=n){
|
||||
if(sign==1){
|
||||
for(j=0;j<b;j++){
|
||||
if(count<=n){
|
||||
array[i][j] = count;}
|
||||
else{
|
||||
break;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
sign*=-1;
|
||||
i++;
|
||||
}
|
||||
else{
|
||||
for(j=b-1;j>=0;j--){
|
||||
if(count<=n){
|
||||
array[i][j]=count;}
|
||||
else{
|
||||
break;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
i++;
|
||||
sign*=-1;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0;i<a;i++){
|
||||
for(j=0;j<b;j++){
|
||||
printf("%lld ",array[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#include<stdio.h>
|
||||
int main(int argc, char *argv[]) {
|
||||
int f=1,a,b,c,i,sum=0;
|
||||
scanf("%d %d %d",&a,&b,&c);
|
||||
if(c==0){
|
||||
if(a==b)
|
||||
printf("YES");
|
||||
else printf("NO");
|
||||
return 0;
|
||||
}
|
||||
if((b-a)%c==0 && (b-a)/c>=0)
|
||||
printf("YES");
|
||||
else
|
||||
printf("NO");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#include<stdio.h>
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i,a[5],b[101]={0},t=0,temp,max=0;
|
||||
for(i=0;i<5;i++)
|
||||
{
|
||||
scanf("%d",&a[i]);
|
||||
b[a[i]]++;
|
||||
t+=a[i];
|
||||
}
|
||||
for(i=0;i<5;i++)
|
||||
{if(b[a[i]]>=3)
|
||||
{
|
||||
max=3*a[i];
|
||||
break;}
|
||||
}
|
||||
for(i=0;i<5;i++)
|
||||
{if(b[a[i]]==2)
|
||||
{temp=a[i]*2;
|
||||
if(temp>max)
|
||||
{
|
||||
max=temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%d",t-max);
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+2449
File diff suppressed because it is too large
Load Diff
+788
@@ -0,0 +1,788 @@
|
||||
/***********************************************************
|
||||
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||
Amsterdam, The Netherlands.
|
||||
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee is hereby granted,
|
||||
provided that the above copyright notice appear in all copies and that
|
||||
both that copyright notice and this permission notice appear in
|
||||
supporting documentation, and that the names of Stichting Mathematisch
|
||||
Centrum or CWI not be used in advertising or publicity pertaining to
|
||||
distribution of the software without specific, written prior permission.
|
||||
|
||||
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
|
||||
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
|
||||
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
******************************************************************/
|
||||
|
||||
/* Mapping object implementation; using a hash table */
|
||||
|
||||
/* This file should really be called "dictobject.c", since "mapping"
|
||||
is the generic name for objects with an unorderred arbitrary key
|
||||
set (just like lists are sequences), but since it improves (and was
|
||||
originally derived from) a file by that name I had to change its
|
||||
name. For the user these objects are still called "dictionaries". */
|
||||
|
||||
#include "allobjects.h"
|
||||
#include "modsupport.h"
|
||||
|
||||
|
||||
/*
|
||||
Table of primes suitable as keys, in ascending order.
|
||||
The first line are the largest primes less than some powers of two,
|
||||
the second line is the largest prime less than 6000,
|
||||
and the third line is a selection from Knuth, Vol. 3, Sec. 6.1, Table 1.
|
||||
The final value is a sentinel and should cause the memory allocation
|
||||
of that many entries to fail (if none of the earlier values cause such
|
||||
failure already).
|
||||
*/
|
||||
static unsigned int primes[] = {
|
||||
3, 7, 13, 31, 61, 127, 251, 509, 1021, 2017, 4093,
|
||||
5987,
|
||||
9551, 15683, 19609, 31397,
|
||||
0xffffffff /* All bits set -- truncation OK */
|
||||
};
|
||||
|
||||
/* Object used as dummy key to fill deleted entries */
|
||||
static object *dummy; /* Initialized by first call to newmappingobject() */
|
||||
|
||||
/*
|
||||
Invariant for entries: when in use, de_value is not NULL and de_key is
|
||||
not NULL and not dummy; when not in use, de_value is NULL and de_key
|
||||
is either NULL or dummy. A dummy key value cannot be replaced by
|
||||
NULL, since otherwise other keys may be lost.
|
||||
*/
|
||||
typedef struct {
|
||||
long me_hash;
|
||||
object *me_key;
|
||||
object *me_value;
|
||||
} mappingentry;
|
||||
|
||||
/*
|
||||
To ensure the lookup algorithm terminates, the table size must be a
|
||||
prime number and there must be at least one NULL key in the table.
|
||||
The value ma_fill is the number of non-NULL keys; ma_used is the number
|
||||
of non-NULL, non-dummy keys.
|
||||
To avoid slowing down lookups on a near-full table, we resize the table
|
||||
when it is more than half filled.
|
||||
*/
|
||||
typedef struct {
|
||||
OB_HEAD
|
||||
int ma_fill;
|
||||
int ma_used;
|
||||
int ma_size;
|
||||
mappingentry *ma_table;
|
||||
} mappingobject;
|
||||
|
||||
object *
|
||||
newmappingobject()
|
||||
{
|
||||
register mappingobject *mp;
|
||||
if (dummy == NULL) { /* Auto-initialize dummy */
|
||||
dummy = newstringobject("<dummy key>");
|
||||
if (dummy == NULL)
|
||||
return NULL;
|
||||
}
|
||||
mp = NEWOBJ(mappingobject, &Mappingtype);
|
||||
if (mp == NULL)
|
||||
return NULL;
|
||||
mp->ma_size = primes[0];
|
||||
mp->ma_table = (mappingentry *) calloc(sizeof(mappingentry), mp->ma_size);
|
||||
if (mp->ma_table == NULL) {
|
||||
DEL(mp);
|
||||
return err_nomem();
|
||||
}
|
||||
mp->ma_fill = 0;
|
||||
mp->ma_used = 0;
|
||||
return (object *)mp;
|
||||
}
|
||||
|
||||
/*
|
||||
The basic lookup function used by all operations.
|
||||
This is essentially Algorithm D from Knuth Vol. 3, Sec. 6.4.
|
||||
Open addressing is preferred over chaining since the link overhead for
|
||||
chaining would be substantial (100% with typical malloc overhead).
|
||||
|
||||
First a 32-bit hash value, 'sum', is computed from the key string.
|
||||
The first character is added an extra time shifted by 8 to avoid hashing
|
||||
single-character keys (often heavily used variables) too close together.
|
||||
All arithmetic on sum should ignore overflow.
|
||||
|
||||
The initial probe index is then computed as sum mod the table size.
|
||||
Subsequent probe indices are incr apart (mod table size), where incr
|
||||
is also derived from sum, with the additional requirement that it is
|
||||
relative prime to the table size (i.e., 1 <= incr < size, since the size
|
||||
is a prime number). My choice for incr is somewhat arbitrary.
|
||||
*/
|
||||
static mappingentry *lookmapping PROTO((mappingobject *, object *, long));
|
||||
static mappingentry *
|
||||
lookmapping(mp, key, hash)
|
||||
register mappingobject *mp;
|
||||
object *key;
|
||||
long hash;
|
||||
{
|
||||
register int i, incr;
|
||||
register unsigned long sum = (unsigned long) hash;
|
||||
register mappingentry *freeslot = NULL;
|
||||
/* We must come up with (i, incr) such that 0 <= i < ma_size
|
||||
and 0 < incr < ma_size and both are a function of hash */
|
||||
i = sum % mp->ma_size;
|
||||
do {
|
||||
sum = sum + sum + sum + 1;
|
||||
incr = sum % mp->ma_size;
|
||||
} while (incr == 0);
|
||||
for (;;) {
|
||||
register mappingentry *ep = &mp->ma_table[i];
|
||||
if (ep->me_key == NULL) {
|
||||
if (freeslot != NULL)
|
||||
return freeslot;
|
||||
else
|
||||
return ep;
|
||||
}
|
||||
if (ep->me_key == dummy) {
|
||||
if (freeslot != NULL)
|
||||
freeslot = ep;
|
||||
}
|
||||
else if (ep->me_hash == hash &&
|
||||
cmpobject(ep->me_key, key) == 0) {
|
||||
return ep;
|
||||
}
|
||||
i = (i + incr) % mp->ma_size;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Internal routine to insert a new item into the table.
|
||||
Used both by the internal resize routine and by the public insert routine.
|
||||
Eats a reference to key and one to value.
|
||||
*/
|
||||
static void insertmapping PROTO((mappingobject *, object *, long, object *));
|
||||
static void
|
||||
insertmapping(mp, key, hash, value)
|
||||
register mappingobject *mp;
|
||||
object *key;
|
||||
long hash;
|
||||
object *value;
|
||||
{
|
||||
register mappingentry *ep;
|
||||
ep = lookmapping(mp, key, hash);
|
||||
if (ep->me_value != NULL) {
|
||||
DECREF(ep->me_value);
|
||||
DECREF(key);
|
||||
}
|
||||
else {
|
||||
if (ep->me_key == NULL)
|
||||
mp->ma_fill++;
|
||||
else
|
||||
DECREF(ep->me_key);
|
||||
ep->me_key = key;
|
||||
ep->me_hash = hash;
|
||||
mp->ma_used++;
|
||||
}
|
||||
ep->me_value = value;
|
||||
}
|
||||
|
||||
/*
|
||||
Restructure the table by allocating a new table and reinserting all
|
||||
items again. When entries have been deleted, the new table may
|
||||
actually be smaller than the old one.
|
||||
*/
|
||||
static int mappingresize PROTO((mappingobject *));
|
||||
static int
|
||||
mappingresize(mp)
|
||||
mappingobject *mp;
|
||||
{
|
||||
register int oldsize = mp->ma_size;
|
||||
register int newsize;
|
||||
register mappingentry *oldtable = mp->ma_table;
|
||||
register mappingentry *newtable;
|
||||
register mappingentry *ep;
|
||||
register int i;
|
||||
newsize = mp->ma_size;
|
||||
for (i = 0; ; i++) {
|
||||
if (primes[i] > mp->ma_used*2) {
|
||||
newsize = primes[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
newtable = (mappingentry *) calloc(sizeof(mappingentry), newsize);
|
||||
if (newtable == NULL) {
|
||||
err_nomem();
|
||||
return -1;
|
||||
}
|
||||
mp->ma_size = newsize;
|
||||
mp->ma_table = newtable;
|
||||
mp->ma_fill = 0;
|
||||
mp->ma_used = 0;
|
||||
for (i = 0, ep = oldtable; i < oldsize; i++, ep++) {
|
||||
if (ep->me_value != NULL)
|
||||
insertmapping(mp,ep->me_key,ep->me_hash,ep->me_value);
|
||||
else {
|
||||
XDECREF(ep->me_key);
|
||||
}
|
||||
}
|
||||
DEL(oldtable);
|
||||
return 0;
|
||||
}
|
||||
|
||||
object *
|
||||
mappinglookup(op, key)
|
||||
object *op;
|
||||
object *key;
|
||||
{
|
||||
long hash;
|
||||
if (!is_mappingobject(op)) {
|
||||
err_badcall();
|
||||
return NULL;
|
||||
}
|
||||
hash = hashobject(key);
|
||||
if (hash == -1)
|
||||
return NULL;
|
||||
return lookmapping((mappingobject *)op, key, hash) -> me_value;
|
||||
}
|
||||
|
||||
int
|
||||
mappinginsert(op, key, value)
|
||||
register object *op;
|
||||
object *key;
|
||||
object *value;
|
||||
{
|
||||
register mappingobject *mp;
|
||||
register long hash;
|
||||
if (!is_mappingobject(op)) {
|
||||
err_badcall();
|
||||
return -1;
|
||||
}
|
||||
hash = hashobject(key);
|
||||
if (hash == -1)
|
||||
return -1;
|
||||
mp = (mappingobject *)op;
|
||||
/* if fill >= 2/3 size, resize */
|
||||
if (mp->ma_fill*3 >= mp->ma_size*2) {
|
||||
if (mappingresize(mp) != 0) {
|
||||
if (mp->ma_fill+1 > mp->ma_size)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
INCREF(value);
|
||||
INCREF(key);
|
||||
insertmapping(mp, key, hash, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
mappingremove(op, key)
|
||||
object *op;
|
||||
object *key;
|
||||
{
|
||||
register mappingobject *mp;
|
||||
register long hash;
|
||||
register mappingentry *ep;
|
||||
if (!is_mappingobject(op)) {
|
||||
err_badcall();
|
||||
return -1;
|
||||
}
|
||||
hash = hashobject(key);
|
||||
if (hash == -1)
|
||||
return -1;
|
||||
mp = (mappingobject *)op;
|
||||
ep = lookmapping(mp, key, hash);
|
||||
if (ep->me_value == NULL) {
|
||||
err_setval(KeyError, key);
|
||||
return -1;
|
||||
}
|
||||
DECREF(ep->me_key);
|
||||
INCREF(dummy);
|
||||
ep->me_key = dummy;
|
||||
DECREF(ep->me_value);
|
||||
ep->me_value = NULL;
|
||||
mp->ma_used--;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
mappingclear(op)
|
||||
object *op;
|
||||
{
|
||||
int i;
|
||||
register mappingobject *mp;
|
||||
if (!is_mappingobject(op))
|
||||
return;
|
||||
mp = (mappingobject *)op;
|
||||
for (i = 0; i < mp->ma_size; i++) {
|
||||
XDECREF(mp->ma_table[i].me_key);
|
||||
XDECREF(mp->ma_table[i].me_value);
|
||||
mp->ma_table[i].me_key = NULL;
|
||||
mp->ma_table[i].me_value = NULL;
|
||||
}
|
||||
mp->ma_used = 0;
|
||||
}
|
||||
|
||||
int
|
||||
mappinggetnext(op, ppos, pkey, pvalue)
|
||||
object *op;
|
||||
int *ppos;
|
||||
object **pkey;
|
||||
object **pvalue;
|
||||
{
|
||||
int i;
|
||||
register mappingobject *mp;
|
||||
if (!is_dictobject(op))
|
||||
return 0;
|
||||
mp = (mappingobject *)op;
|
||||
i = *ppos;
|
||||
if (i < 0)
|
||||
return 0;
|
||||
while (i < mp->ma_size && mp->ma_table[i].me_value == NULL)
|
||||
i++;
|
||||
*ppos = i+1;
|
||||
if (i >= mp->ma_size)
|
||||
return 0;
|
||||
if (pkey)
|
||||
*pkey = mp->ma_table[i].me_key;
|
||||
if (pvalue)
|
||||
*pvalue = mp->ma_table[i].me_value;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Methods */
|
||||
|
||||
static void
|
||||
mapping_dealloc(mp)
|
||||
register mappingobject *mp;
|
||||
{
|
||||
register int i;
|
||||
register mappingentry *ep;
|
||||
for (i = 0, ep = mp->ma_table; i < mp->ma_size; i++, ep++) {
|
||||
if (ep->me_key != NULL)
|
||||
DECREF(ep->me_key);
|
||||
if (ep->me_value != NULL)
|
||||
DECREF(ep->me_value);
|
||||
}
|
||||
if (mp->ma_table != NULL)
|
||||
DEL(mp->ma_table);
|
||||
DEL(mp);
|
||||
}
|
||||
|
||||
static int
|
||||
mapping_print(mp, fp, flags)
|
||||
register mappingobject *mp;
|
||||
register FILE *fp;
|
||||
register int flags;
|
||||
{
|
||||
register int i;
|
||||
register int any;
|
||||
register mappingentry *ep;
|
||||
fprintf(fp, "{");
|
||||
any = 0;
|
||||
for (i = 0, ep = mp->ma_table; i < mp->ma_size; i++, ep++) {
|
||||
if (ep->me_value != NULL) {
|
||||
if (any++ > 0)
|
||||
fprintf(fp, ", ");
|
||||
if (printobject((object *)ep->me_key, fp, flags) != 0)
|
||||
return -1;
|
||||
fprintf(fp, ": ");
|
||||
if (printobject(ep->me_value, fp, flags) != 0)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
fprintf(fp, "}");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
js(pv, w)
|
||||
object **pv;
|
||||
object *w;
|
||||
{
|
||||
joinstring(pv, w);
|
||||
XDECREF(w);
|
||||
}
|
||||
|
||||
static object *
|
||||
mapping_repr(mp)
|
||||
mappingobject *mp;
|
||||
{
|
||||
auto object *v;
|
||||
object *sepa, *colon;
|
||||
register int i;
|
||||
register int any;
|
||||
register mappingentry *ep;
|
||||
v = newstringobject("{");
|
||||
sepa = newstringobject(", ");
|
||||
colon = newstringobject(": ");
|
||||
any = 0;
|
||||
for (i = 0, ep = mp->ma_table; i < mp->ma_size; i++, ep++) {
|
||||
if (ep->me_value != NULL) {
|
||||
if (any++)
|
||||
joinstring(&v, sepa);
|
||||
js(&v, reprobject(ep->me_key));
|
||||
joinstring(&v, colon);
|
||||
js(&v, reprobject(ep->me_value));
|
||||
}
|
||||
}
|
||||
js(&v, newstringobject("}"));
|
||||
XDECREF(sepa);
|
||||
XDECREF(colon);
|
||||
return v;
|
||||
}
|
||||
|
||||
static int
|
||||
mapping_length(mp)
|
||||
mappingobject *mp;
|
||||
{
|
||||
return mp->ma_used;
|
||||
}
|
||||
|
||||
static object *
|
||||
mapping_subscript(mp, key)
|
||||
mappingobject *mp;
|
||||
register object *key;
|
||||
{
|
||||
object *v;
|
||||
long hash = hashobject(key);
|
||||
if (hash == -1)
|
||||
return NULL;
|
||||
v = lookmapping(mp, key, hash) -> me_value;
|
||||
if (v == NULL)
|
||||
err_setval(KeyError, key);
|
||||
else
|
||||
INCREF(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
static int
|
||||
mapping_ass_sub(mp, v, w)
|
||||
mappingobject *mp;
|
||||
object *v, *w;
|
||||
{
|
||||
if (w == NULL)
|
||||
return mappingremove((object *)mp, v);
|
||||
else
|
||||
return mappinginsert((object *)mp, v, w);
|
||||
}
|
||||
|
||||
static mapping_methods mapping_as_mapping = {
|
||||
mapping_length, /*mp_length*/
|
||||
mapping_subscript, /*mp_subscript*/
|
||||
mapping_ass_sub, /*mp_ass_subscript*/
|
||||
};
|
||||
|
||||
static object *
|
||||
mapping_keys(mp, args)
|
||||
register mappingobject *mp;
|
||||
object *args;
|
||||
{
|
||||
register object *v;
|
||||
register int i, j;
|
||||
if (!getnoarg(args))
|
||||
return NULL;
|
||||
v = newlistobject(mp->ma_used);
|
||||
if (v == NULL)
|
||||
return NULL;
|
||||
for (i = 0, j = 0; i < mp->ma_size; i++) {
|
||||
if (mp->ma_table[i].me_value != NULL) {
|
||||
object *key = mp->ma_table[i].me_key;
|
||||
INCREF(key);
|
||||
setlistitem(v, j, key);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
static object *
|
||||
mapping_values(mp, args)
|
||||
register mappingobject *mp;
|
||||
object *args;
|
||||
{
|
||||
register object *v;
|
||||
register int i, j;
|
||||
if (!getnoarg(args))
|
||||
return NULL;
|
||||
v = newlistobject(mp->ma_used);
|
||||
if (v == NULL)
|
||||
return NULL;
|
||||
for (i = 0, j = 0; i < mp->ma_size; i++) {
|
||||
if (mp->ma_table[i].me_value != NULL) {
|
||||
object *value = mp->ma_table[i].me_value;
|
||||
INCREF(value);
|
||||
setlistitem(v, j, value);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
static object *
|
||||
mapping_items(mp, args)
|
||||
register mappingobject *mp;
|
||||
object *args;
|
||||
{
|
||||
register object *v;
|
||||
register int i, j;
|
||||
if (!getnoarg(args))
|
||||
return NULL;
|
||||
v = newlistobject(mp->ma_used);
|
||||
if (v == NULL)
|
||||
return NULL;
|
||||
for (i = 0, j = 0; i < mp->ma_size; i++) {
|
||||
if (mp->ma_table[i].me_value != NULL) {
|
||||
object *key = mp->ma_table[i].me_key;
|
||||
object *value = mp->ma_table[i].me_value;
|
||||
object *item = newtupleobject(2);
|
||||
if (item == NULL) {
|
||||
DECREF(v);
|
||||
return NULL;
|
||||
}
|
||||
INCREF(key);
|
||||
settupleitem(item, 0, key);
|
||||
INCREF(value);
|
||||
settupleitem(item, 1, value);
|
||||
setlistitem(v, j, item);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
object *
|
||||
getmappingkeys(mp)
|
||||
object *mp;
|
||||
{
|
||||
if (mp == NULL || !is_mappingobject(mp)) {
|
||||
err_badcall();
|
||||
return NULL;
|
||||
}
|
||||
return mapping_keys((mappingobject *)mp, (object *)NULL);
|
||||
}
|
||||
|
||||
object *
|
||||
getmappingvalues(mp)
|
||||
object *mp;
|
||||
{
|
||||
if (mp == NULL || !is_mappingobject(mp)) {
|
||||
err_badcall();
|
||||
return NULL;
|
||||
}
|
||||
return mapping_values((mappingobject *)mp, (object *)NULL);
|
||||
}
|
||||
|
||||
object *
|
||||
getmappingitems(mp)
|
||||
object *mp;
|
||||
{
|
||||
if (mp == NULL || !is_mappingobject(mp)) {
|
||||
err_badcall();
|
||||
return NULL;
|
||||
}
|
||||
return mapping_values((mappingobject *)mp, (object *)NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
mapping_compare(a, b)
|
||||
mappingobject *a, *b;
|
||||
{
|
||||
object *akeys, *bkeys;
|
||||
int i, n, res;
|
||||
if (a == b)
|
||||
return 0;
|
||||
if (a->ma_used == 0) {
|
||||
if (b->ma_used != 0)
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
if (b->ma_used == 0)
|
||||
return 1;
|
||||
}
|
||||
akeys = mapping_keys(a, (object *)NULL);
|
||||
bkeys = mapping_keys(b, (object *)NULL);
|
||||
if (akeys == NULL || bkeys == NULL) {
|
||||
/* Oops, out of memory -- what to do? */
|
||||
/* For now, sort on address! */
|
||||
XDECREF(akeys);
|
||||
XDECREF(bkeys);
|
||||
if (a < b)
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
sortlist(akeys);
|
||||
sortlist(bkeys);
|
||||
n = a->ma_used < b->ma_used ? a->ma_used : b->ma_used; /* smallest */
|
||||
res = 0;
|
||||
for (i = 0; i < n; i++) {
|
||||
object *akey, *bkey, *aval, *bval;
|
||||
long ahash, bhash;
|
||||
akey = getlistitem(akeys, i);
|
||||
bkey = getlistitem(bkeys, i);
|
||||
res = cmpobject(akey, bkey);
|
||||
if (res != 0)
|
||||
break;
|
||||
ahash = hashobject(akey);
|
||||
if (ahash == -1)
|
||||
err_clear(); /* Don't want errors here */
|
||||
bhash = hashobject(bkey);
|
||||
if (bhash == -1)
|
||||
err_clear(); /* Don't want errors here */
|
||||
aval = lookmapping(a, akey, ahash) -> me_value;
|
||||
bval = lookmapping(b, bkey, bhash) -> me_value;
|
||||
res = cmpobject(aval, bval);
|
||||
if (res != 0)
|
||||
break;
|
||||
}
|
||||
if (res == 0) {
|
||||
if (a->ma_used < b->ma_used)
|
||||
res = -1;
|
||||
else if (a->ma_used > b->ma_used)
|
||||
res = 1;
|
||||
}
|
||||
DECREF(akeys);
|
||||
DECREF(bkeys);
|
||||
return res;
|
||||
}
|
||||
|
||||
static object *
|
||||
mapping_has_key(mp, args)
|
||||
register mappingobject *mp;
|
||||
object *args;
|
||||
{
|
||||
object *key;
|
||||
long hash;
|
||||
register long ok;
|
||||
if (!getargs(args, "O", &key))
|
||||
return NULL;
|
||||
hash = hashobject(key);
|
||||
if (hash == -1)
|
||||
return NULL;
|
||||
ok = lookmapping(mp, key, hash)->me_value != NULL;
|
||||
return newintobject(ok);
|
||||
}
|
||||
|
||||
static struct methodlist mapp_methods[] = {
|
||||
{"has_key", mapping_has_key},
|
||||
{"items", mapping_items},
|
||||
{"keys", mapping_keys},
|
||||
{"values", mapping_values},
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static object *
|
||||
mapping_getattr(mp, name)
|
||||
mappingobject *mp;
|
||||
char *name;
|
||||
{
|
||||
return findmethod(mapp_methods, (object *)mp, name);
|
||||
}
|
||||
|
||||
typeobject Mappingtype = {
|
||||
OB_HEAD_INIT(&Typetype)
|
||||
0,
|
||||
"dictionary",
|
||||
sizeof(mappingobject),
|
||||
0,
|
||||
mapping_dealloc, /*tp_dealloc*/
|
||||
mapping_print, /*tp_print*/
|
||||
mapping_getattr, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
mapping_compare, /*tp_compare*/
|
||||
mapping_repr, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
&mapping_as_mapping, /*tp_as_mapping*/
|
||||
};
|
||||
|
||||
/* For backward compatibility with old dictionary interface */
|
||||
|
||||
static object *last_name_object;
|
||||
static char *last_name_char;
|
||||
|
||||
object *
|
||||
getattro(v, name)
|
||||
object *v;
|
||||
object *name;
|
||||
{
|
||||
if (name != last_name_object) {
|
||||
XDECREF(last_name_object);
|
||||
INCREF(name);
|
||||
last_name_object = name;
|
||||
last_name_char = getstringvalue(name);
|
||||
}
|
||||
return getattr(v, last_name_char);
|
||||
}
|
||||
|
||||
int
|
||||
setattro(v, name, value)
|
||||
object *v;
|
||||
object *name;
|
||||
object *value;
|
||||
{
|
||||
if (name != last_name_object) {
|
||||
XDECREF(last_name_object);
|
||||
INCREF(name);
|
||||
last_name_object = name;
|
||||
last_name_char = getstringvalue(name);
|
||||
}
|
||||
return setattr(v, last_name_char, value);
|
||||
}
|
||||
|
||||
object *
|
||||
dictlookup(v, key)
|
||||
object *v;
|
||||
char *key;
|
||||
{
|
||||
if (key != last_name_char) {
|
||||
XDECREF(last_name_object);
|
||||
last_name_object = newstringobject(key);
|
||||
if (last_name_object == NULL) {
|
||||
last_name_char = NULL;
|
||||
return NULL;
|
||||
}
|
||||
last_name_char = key;
|
||||
}
|
||||
return mappinglookup(v, last_name_object);
|
||||
}
|
||||
|
||||
int
|
||||
dictinsert(v, key, item)
|
||||
object *v;
|
||||
char *key;
|
||||
object *item;
|
||||
{
|
||||
if (key != last_name_char) {
|
||||
XDECREF(last_name_object);
|
||||
last_name_object = newstringobject(key);
|
||||
if (last_name_object == NULL) {
|
||||
last_name_char = NULL;
|
||||
return NULL;
|
||||
}
|
||||
last_name_char = key;
|
||||
}
|
||||
return mappinginsert(v, last_name_object, item);
|
||||
}
|
||||
|
||||
int
|
||||
dictremove(v, key)
|
||||
object *v;
|
||||
char *key;
|
||||
{
|
||||
if (key != last_name_char) {
|
||||
XDECREF(last_name_object);
|
||||
last_name_object = newstringobject(key);
|
||||
if (last_name_object == NULL) {
|
||||
last_name_char = NULL;
|
||||
return NULL;
|
||||
}
|
||||
last_name_char = key;
|
||||
}
|
||||
return mappingremove(v, last_name_object);
|
||||
}
|
||||
+8162
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,458 @@
|
||||
/***********************************************************
|
||||
Copyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
|
||||
Netherlands.
|
||||
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee is hereby granted,
|
||||
provided that the above copyright notice appear in all copies and that
|
||||
both that copyright notice and this permission notice appear in
|
||||
supporting documentation, and that the names of Stichting Mathematisch
|
||||
Centrum or CWI not be used in advertising or publicity pertaining to
|
||||
distribution of the software without specific, written prior permission.
|
||||
|
||||
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
|
||||
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
|
||||
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
******************************************************************/
|
||||
|
||||
/* Integer object implementation */
|
||||
|
||||
#include "allobjects.h"
|
||||
|
||||
/* Standard Booleans */
|
||||
|
||||
intobject FalseObject = {
|
||||
OB_HEAD_INIT(&Inttype)
|
||||
0
|
||||
};
|
||||
|
||||
intobject TrueObject = {
|
||||
OB_HEAD_INIT(&Inttype)
|
||||
1
|
||||
};
|
||||
|
||||
static object *
|
||||
err_ovf(msg)
|
||||
char *msg;
|
||||
{
|
||||
err_setstr(OverflowError, msg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Integers are quite normal objects, to make object handling uniform.
|
||||
(Using odd pointers to represent integers would save much space
|
||||
but require extra checks for this special case throughout the code.)
|
||||
Since, a typical Python program spends much of its time allocating
|
||||
and deallocating integers, these operations should be very fast.
|
||||
Therefore we use a dedicated allocation scheme with a much lower
|
||||
overhead (in space and time) than straight malloc(): a simple
|
||||
dedicated free list, filled when necessary with memory from malloc().
|
||||
*/
|
||||
|
||||
#define BLOCK_SIZE 1000 /* 1K less typical malloc overhead */
|
||||
#define N_INTOBJECTS (BLOCK_SIZE / sizeof(intobject))
|
||||
|
||||
static intobject *
|
||||
fill_free_list()
|
||||
{
|
||||
intobject *p, *q;
|
||||
p = NEW(intobject, N_INTOBJECTS);
|
||||
if (p == NULL)
|
||||
return (intobject *)err_nomem();
|
||||
q = p + N_INTOBJECTS;
|
||||
while (--q > p)
|
||||
*(intobject **)q = q-1;
|
||||
*(intobject **)q = NULL;
|
||||
return p + N_INTOBJECTS - 1;
|
||||
}
|
||||
|
||||
static intobject *free_list = NULL;
|
||||
|
||||
object *
|
||||
newintobject(ival)
|
||||
long ival;
|
||||
{
|
||||
register intobject *v;
|
||||
if (free_list == NULL) {
|
||||
if ((free_list = fill_free_list()) == NULL)
|
||||
return NULL;
|
||||
}
|
||||
v = free_list;
|
||||
free_list = *(intobject **)free_list;
|
||||
NEWREF(v);
|
||||
v->ob_type = &Inttype;
|
||||
v->ob_ival = ival;
|
||||
return (object *) v;
|
||||
}
|
||||
|
||||
static void
|
||||
int_dealloc(v)
|
||||
intobject *v;
|
||||
{
|
||||
*(intobject **)v = free_list;
|
||||
free_list = v;
|
||||
}
|
||||
|
||||
long
|
||||
getintvalue(op)
|
||||
register object *op;
|
||||
{
|
||||
if (!is_intobject(op)) {
|
||||
err_badcall();
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
return ((intobject *)op) -> ob_ival;
|
||||
}
|
||||
|
||||
/* Methods */
|
||||
|
||||
static int
|
||||
int_print(v, fp, flags)
|
||||
intobject *v;
|
||||
FILE *fp;
|
||||
int flags;
|
||||
{
|
||||
fprintf(fp, "%ld", v->ob_ival);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static object *
|
||||
int_repr(v)
|
||||
intobject *v;
|
||||
{
|
||||
char buf[20];
|
||||
sprintf(buf, "%ld", v->ob_ival);
|
||||
return newstringobject(buf);
|
||||
}
|
||||
|
||||
static int
|
||||
int_compare(v, w)
|
||||
intobject *v, *w;
|
||||
{
|
||||
register long i = v->ob_ival;
|
||||
register long j = w->ob_ival;
|
||||
return (i < j) ? -1 : (i > j) ? 1 : 0;
|
||||
}
|
||||
|
||||
static object *
|
||||
int_add(v, w)
|
||||
intobject *v;
|
||||
intobject *w;
|
||||
{
|
||||
register long a, b, x;
|
||||
a = v->ob_ival;
|
||||
b = w->ob_ival;
|
||||
x = a + b;
|
||||
if ((x^a) < 0 && (x^b) < 0)
|
||||
return err_ovf("integer addition");
|
||||
return newintobject(x);
|
||||
}
|
||||
|
||||
static object *
|
||||
int_sub(v, w)
|
||||
intobject *v;
|
||||
intobject *w;
|
||||
{
|
||||
register long a, b, x;
|
||||
a = v->ob_ival;
|
||||
b = w->ob_ival;
|
||||
x = a - b;
|
||||
if ((x^a) < 0 && (x^~b) < 0)
|
||||
return err_ovf("integer subtraction");
|
||||
return newintobject(x);
|
||||
}
|
||||
|
||||
static object *
|
||||
int_mul(v, w)
|
||||
intobject *v;
|
||||
intobject *w;
|
||||
{
|
||||
register long a, b;
|
||||
double x;
|
||||
a = v->ob_ival;
|
||||
b = w->ob_ival;
|
||||
x = (double)a * (double)b;
|
||||
if (x > 0x7fffffff || x < (double) (long) 0x80000000)
|
||||
return err_ovf("integer multiplication");
|
||||
return newintobject(a * b);
|
||||
}
|
||||
|
||||
static int
|
||||
i_divmod(x, y, p_xdivy, p_xmody)
|
||||
register intobject *x, *y;
|
||||
long *p_xdivy, *p_xmody;
|
||||
{
|
||||
long xi = x->ob_ival;
|
||||
long yi = y->ob_ival;
|
||||
long xdivy, xmody;
|
||||
|
||||
if (yi == 0) {
|
||||
err_setstr(ZeroDivisionError, "integer division or modulo");
|
||||
return -1;
|
||||
}
|
||||
if (yi < 0) {
|
||||
if (xi < 0)
|
||||
xdivy = -xi / -yi;
|
||||
else
|
||||
xdivy = - (xi / -yi);
|
||||
}
|
||||
else {
|
||||
if (xi < 0)
|
||||
xdivy = - (-xi / yi);
|
||||
else
|
||||
xdivy = xi / yi;
|
||||
}
|
||||
xmody = xi - xdivy*yi;
|
||||
if (xmody < 0 && yi > 0 || xmody > 0 && yi < 0) {
|
||||
xmody += yi;
|
||||
xdivy -= 1;
|
||||
}
|
||||
*p_xdivy = xdivy;
|
||||
*p_xmody = xmody;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static object *
|
||||
int_div(x, y)
|
||||
intobject *x;
|
||||
intobject *y;
|
||||
{
|
||||
long d, m;
|
||||
if (i_divmod(x, y, &d, &m) < 0)
|
||||
return NULL;
|
||||
return newintobject(d);
|
||||
}
|
||||
|
||||
static object *
|
||||
int_mod(x, y)
|
||||
intobject *x;
|
||||
intobject *y;
|
||||
{
|
||||
long d, m;
|
||||
if (i_divmod(x, y, &d, &m) < 0)
|
||||
return NULL;
|
||||
newintobject(m);
|
||||
}
|
||||
|
||||
static object *
|
||||
int_divmod(x, y)
|
||||
intobject *x;
|
||||
intobject *y;
|
||||
{
|
||||
object *v, *v0, *v1;
|
||||
long d, m;
|
||||
if (i_divmod(x, y, &d, &m) < 0)
|
||||
return NULL;
|
||||
v = newtupleobject(2);
|
||||
v0 = newintobject(d);
|
||||
v1 = newintobject(m);
|
||||
if (v == NULL || v0 == NULL || v1 == NULL ||
|
||||
settupleitem(v, 0, v0) != 0 ||
|
||||
settupleitem(v, 1, v1) != 0) {
|
||||
XDECREF(v);
|
||||
XDECREF(v0);
|
||||
XDECREF(v1);
|
||||
v = NULL;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
static object *
|
||||
int_pow(v, w)
|
||||
intobject *v;
|
||||
intobject *w;
|
||||
{
|
||||
register long iv, iw, ix;
|
||||
iv = v->ob_ival;
|
||||
iw = w->ob_ival;
|
||||
if (iw < 0) {
|
||||
err_setstr(ValueError, "integer to the negative power");
|
||||
return NULL;
|
||||
}
|
||||
ix = 1;
|
||||
while (--iw >= 0) {
|
||||
long prev = ix;
|
||||
ix = ix * iv;
|
||||
if (iv == 0)
|
||||
break; /* 0 to some power -- avoid ix / 0 */
|
||||
if (ix / iv != prev)
|
||||
return err_ovf("integer pow()");
|
||||
}
|
||||
return newintobject(ix);
|
||||
}
|
||||
|
||||
static object *
|
||||
int_neg(v)
|
||||
intobject *v;
|
||||
{
|
||||
register long a, x;
|
||||
a = v->ob_ival;
|
||||
x = -a;
|
||||
if (a < 0 && x < 0)
|
||||
return err_ovf("integer negation");
|
||||
return newintobject(x);
|
||||
}
|
||||
|
||||
static object *
|
||||
int_pos(v)
|
||||
intobject *v;
|
||||
{
|
||||
INCREF(v);
|
||||
return (object *)v;
|
||||
}
|
||||
|
||||
static object *
|
||||
int_abs(v)
|
||||
intobject *v;
|
||||
{
|
||||
if (v->ob_ival >= 0)
|
||||
return int_pos(v);
|
||||
else
|
||||
return int_neg(v);
|
||||
}
|
||||
|
||||
static int
|
||||
int_nonzero(v)
|
||||
intobject *v;
|
||||
{
|
||||
return v->ob_ival != 0;
|
||||
}
|
||||
|
||||
static object *
|
||||
int_invert(v)
|
||||
intobject *v;
|
||||
{
|
||||
return newintobject(~v->ob_ival);
|
||||
}
|
||||
|
||||
static object *
|
||||
int_lshift(v, w)
|
||||
intobject *v;
|
||||
intobject *w;
|
||||
{
|
||||
register long a, b;
|
||||
a = v->ob_ival;
|
||||
b = w->ob_ival;
|
||||
if (b < 0) {
|
||||
err_setstr(ValueError, "negative shift count");
|
||||
return NULL;
|
||||
}
|
||||
if (a == 0 || b == 0) {
|
||||
INCREF(v);
|
||||
return (object *) v;
|
||||
}
|
||||
if (b >= 32) {
|
||||
return newintobject(0L);
|
||||
}
|
||||
a = (unsigned long)a << b;
|
||||
return newintobject(a);
|
||||
}
|
||||
|
||||
static object *
|
||||
int_rshift(v, w)
|
||||
intobject *v;
|
||||
intobject *w;
|
||||
{
|
||||
register long a, b;
|
||||
a = v->ob_ival;
|
||||
b = w->ob_ival;
|
||||
if (b < 0) {
|
||||
err_setstr(ValueError, "negative shift count");
|
||||
return NULL;
|
||||
}
|
||||
if (a == 0 || b == 0) {
|
||||
INCREF(v);
|
||||
return (object *) v;
|
||||
}
|
||||
if (b >= 32) {
|
||||
if (a < 0)
|
||||
a = -1;
|
||||
else
|
||||
a = 0;
|
||||
}
|
||||
else {
|
||||
if (a < 0)
|
||||
a = ~( ~(unsigned long)a >> b );
|
||||
else
|
||||
a = (unsigned long)a >> b;
|
||||
}
|
||||
return newintobject(a);
|
||||
}
|
||||
|
||||
static object *
|
||||
int_and(v, w)
|
||||
intobject *v;
|
||||
intobject *w;
|
||||
{
|
||||
register long a, b;
|
||||
a = v->ob_ival;
|
||||
b = w->ob_ival;
|
||||
return newintobject(a & b);
|
||||
}
|
||||
|
||||
static object *
|
||||
int_xor(v, w)
|
||||
intobject *v;
|
||||
intobject *w;
|
||||
{
|
||||
register long a, b;
|
||||
a = v->ob_ival;
|
||||
b = w->ob_ival;
|
||||
return newintobject(a ^ b);
|
||||
}
|
||||
|
||||
static object *
|
||||
int_or(v, w)
|
||||
intobject *v;
|
||||
intobject *w;
|
||||
{
|
||||
register long a, b;
|
||||
a = v->ob_ival;
|
||||
b = w->ob_ival;
|
||||
return newintobject(a | b);
|
||||
}
|
||||
|
||||
static number_methods int_as_number = {
|
||||
int_add, /*nb_add*/
|
||||
int_sub, /*nb_subtract*/
|
||||
int_mul, /*nb_multiply*/
|
||||
int_div, /*nb_divide*/
|
||||
int_mod, /*nb_remainder*/
|
||||
int_divmod, /*nb_divmod*/
|
||||
int_pow, /*nb_power*/
|
||||
int_neg, /*nb_negative*/
|
||||
int_pos, /*nb_positive*/
|
||||
int_abs, /*nb_absolute*/
|
||||
int_nonzero, /*nb_nonzero*/
|
||||
int_invert, /*nb_invert*/
|
||||
int_lshift, /*nb_lshift*/
|
||||
int_rshift, /*nb_rshift*/
|
||||
int_and, /*nb_and*/
|
||||
int_xor, /*nb_xor*/
|
||||
int_or, /*nb_or*/
|
||||
};
|
||||
|
||||
typeobject Inttype = {
|
||||
OB_HEAD_INIT(&Typetype)
|
||||
0,
|
||||
"int",
|
||||
sizeof(intobject),
|
||||
0,
|
||||
int_dealloc, /*tp_dealloc*/
|
||||
int_print, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
int_compare, /*tp_compare*/
|
||||
int_repr, /*tp_repr*/
|
||||
&int_as_number, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
};
|
||||
+3486
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,788 @@
|
||||
/***********************************************************
|
||||
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||
Amsterdam, The Netherlands.
|
||||
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee is hereby granted,
|
||||
provided that the above copyright notice appear in all copies and that
|
||||
both that copyright notice and this permission notice appear in
|
||||
supporting documentation, and that the names of Stichting Mathematisch
|
||||
Centrum or CWI not be used in advertising or publicity pertaining to
|
||||
distribution of the software without specific, written prior permission.
|
||||
|
||||
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
|
||||
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
|
||||
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
******************************************************************/
|
||||
|
||||
/* Mapping object implementation; using a hash table */
|
||||
|
||||
/* This file should really be called "dictobject.c", since "mapping"
|
||||
is the generic name for objects with an unorderred arbitrary key
|
||||
set (just like lists are sequences), but since it improves (and was
|
||||
originally derived from) a file by that name I had to change its
|
||||
name. For the user these objects are still called "dictionaries". */
|
||||
|
||||
#include "allobjects.h"
|
||||
#include "modsupport.h"
|
||||
|
||||
|
||||
/*
|
||||
Table of primes suitable as keys, in ascending order.
|
||||
The first line are the largest primes less than some powers of two,
|
||||
the second line is the largest prime less than 6000,
|
||||
and the third line is a selection from Knuth, Vol. 3, Sec. 6.1, Table 1.
|
||||
The final value is a sentinel and should cause the memory allocation
|
||||
of that many entries to fail (if none of the earlier values cause such
|
||||
failure already).
|
||||
*/
|
||||
static unsigned int primes[] = {
|
||||
3, 7, 13, 31, 61, 127, 251, 509, 1021, 2017, 4093,
|
||||
5987,
|
||||
9551, 15683, 19609, 31397,
|
||||
0xffffffff /* All bits set -- truncation OK */
|
||||
};
|
||||
|
||||
/* Object used as dummy key to fill deleted entries */
|
||||
static object *dummy; /* Initialized by first call to newmappingobject() */
|
||||
|
||||
/*
|
||||
Invariant for entries: when in use, de_value is not NULL and de_key is
|
||||
not NULL and not dummy; when not in use, de_value is NULL and de_key
|
||||
is either NULL or dummy. A dummy key value cannot be replaced by
|
||||
NULL, since otherwise other keys may be lost.
|
||||
*/
|
||||
typedef struct {
|
||||
long me_hash;
|
||||
object *me_key;
|
||||
object *me_value;
|
||||
} mappingentry;
|
||||
|
||||
/*
|
||||
To ensure the lookup algorithm terminates, the table size must be a
|
||||
prime number and there must be at least one NULL key in the table.
|
||||
The value ma_fill is the number of non-NULL keys; ma_used is the number
|
||||
of non-NULL, non-dummy keys.
|
||||
To avoid slowing down lookups on a near-full table, we resize the table
|
||||
when it is more than half filled.
|
||||
*/
|
||||
typedef struct {
|
||||
OB_HEAD
|
||||
int ma_fill;
|
||||
int ma_used;
|
||||
int ma_size;
|
||||
mappingentry *ma_table;
|
||||
} mappingobject;
|
||||
|
||||
object *
|
||||
newmappingobject()
|
||||
{
|
||||
register mappingobject *mp;
|
||||
if (dummy == NULL) { /* Auto-initialize dummy */
|
||||
dummy = newstringobject("<dummy key>");
|
||||
if (dummy == NULL)
|
||||
return NULL;
|
||||
}
|
||||
mp = NEWOBJ(mappingobject, &Mappingtype);
|
||||
if (mp == NULL)
|
||||
return NULL;
|
||||
mp->ma_size = primes[0];
|
||||
mp->ma_table = (mappingentry *) calloc(sizeof(mappingentry), mp->ma_size);
|
||||
if (mp->ma_table == NULL) {
|
||||
DEL(mp);
|
||||
return err_nomem();
|
||||
}
|
||||
mp->ma_fill = 0;
|
||||
mp->ma_used = 0;
|
||||
return (object *)mp;
|
||||
}
|
||||
|
||||
/*
|
||||
The basic lookup function used by all operations.
|
||||
This is essentially Algorithm D from Knuth Vol. 3, Sec. 6.4.
|
||||
Open addressing is preferred over chaining since the link overhead for
|
||||
chaining would be substantial (100% with typical malloc overhead).
|
||||
|
||||
First a 32-bit hash value, 'sum', is computed from the key string.
|
||||
The first character is added an extra time shifted by 8 to avoid hashing
|
||||
single-character keys (often heavily used variables) too close together.
|
||||
All arithmetic on sum should ignore overflow.
|
||||
|
||||
The initial probe index is then computed as sum mod the table size.
|
||||
Subsequent probe indices are incr apart (mod table size), where incr
|
||||
is also derived from sum, with the additional requirement that it is
|
||||
relative prime to the table size (i.e., 1 <= incr < size, since the size
|
||||
is a prime number). My choice for incr is somewhat arbitrary.
|
||||
*/
|
||||
static mappingentry *lookmapping PROTO((mappingobject *, object *, long));
|
||||
static mappingentry *
|
||||
lookmapping(mp, key, hash)
|
||||
register mappingobject *mp;
|
||||
object *key;
|
||||
long hash;
|
||||
{
|
||||
register int i, incr;
|
||||
register unsigned long sum = (unsigned long) hash;
|
||||
register mappingentry *freeslot = NULL;
|
||||
/* We must come up with (i, incr) such that 0 <= i < ma_size
|
||||
and 0 < incr < ma_size and both are a function of hash */
|
||||
i = sum % mp->ma_size;
|
||||
do {
|
||||
sum = sum + sum + sum + 1;
|
||||
incr = sum % mp->ma_size;
|
||||
} while (incr == 0);
|
||||
for (;;) {
|
||||
register mappingentry *ep = &mp->ma_table[i];
|
||||
if (ep->me_key == NULL) {
|
||||
if (freeslot != NULL)
|
||||
return freeslot;
|
||||
else
|
||||
return ep;
|
||||
}
|
||||
if (ep->me_key == dummy) {
|
||||
if (freeslot != NULL)
|
||||
freeslot = ep;
|
||||
}
|
||||
else if (ep->me_hash == hash &&
|
||||
cmpobject(ep->me_key, key) == 0) {
|
||||
return ep;
|
||||
}
|
||||
i = (i + incr) % mp->ma_size;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Internal routine to insert a new item into the table.
|
||||
Used both by the internal resize routine and by the public insert routine.
|
||||
Eats a reference to key and one to value.
|
||||
*/
|
||||
static void insertmapping PROTO((mappingobject *, object *, long, object *));
|
||||
static void
|
||||
insertmapping(mp, key, hash, value)
|
||||
register mappingobject *mp;
|
||||
object *key;
|
||||
long hash;
|
||||
object *value;
|
||||
{
|
||||
register mappingentry *ep;
|
||||
ep = lookmapping(mp, key, hash);
|
||||
if (ep->me_value != NULL) {
|
||||
DECREF(ep->me_value);
|
||||
DECREF(key);
|
||||
}
|
||||
else {
|
||||
if (ep->me_key == NULL)
|
||||
mp->ma_fill++;
|
||||
else
|
||||
DECREF(ep->me_key);
|
||||
ep->me_key = key;
|
||||
ep->me_hash = hash;
|
||||
mp->ma_used++;
|
||||
}
|
||||
ep->me_value = value;
|
||||
}
|
||||
|
||||
/*
|
||||
Restructure the table by allocating a new table and reinserting all
|
||||
items again. When entries have been deleted, the new table may
|
||||
actually be smaller than the old one.
|
||||
*/
|
||||
static int mappingresize PROTO((mappingobject *));
|
||||
static int
|
||||
mappingresize(mp)
|
||||
mappingobject *mp;
|
||||
{
|
||||
register int oldsize = mp->ma_size;
|
||||
register int newsize;
|
||||
register mappingentry *oldtable = mp->ma_table;
|
||||
register mappingentry *newtable;
|
||||
register mappingentry *ep;
|
||||
register int i;
|
||||
newsize = mp->ma_size;
|
||||
for (i = 0; ; i++) {
|
||||
if (primes[i] > mp->ma_used*2) {
|
||||
newsize = primes[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
newtable = (mappingentry *) calloc(sizeof(mappingentry), newsize);
|
||||
if (newtable == NULL) {
|
||||
err_nomem();
|
||||
return -1;
|
||||
}
|
||||
mp->ma_size = newsize;
|
||||
mp->ma_table = newtable;
|
||||
mp->ma_fill = 0;
|
||||
mp->ma_used = 0;
|
||||
for (i = 0, ep = oldtable; i < oldsize; i++, ep++) {
|
||||
if (ep->me_value != NULL)
|
||||
insertmapping(mp,ep->me_key,ep->me_hash,ep->me_value);
|
||||
else {
|
||||
XDECREF(ep->me_key);
|
||||
}
|
||||
}
|
||||
DEL(oldtable);
|
||||
return 0;
|
||||
}
|
||||
|
||||
object *
|
||||
mappinglookup(op, key)
|
||||
object *op;
|
||||
object *key;
|
||||
{
|
||||
long hash;
|
||||
if (!is_mappingobject(op)) {
|
||||
err_badcall();
|
||||
return NULL;
|
||||
}
|
||||
hash = hashobject(key);
|
||||
if (hash == -1)
|
||||
return NULL;
|
||||
return lookmapping((mappingobject *)op, key, hash) -> me_value;
|
||||
}
|
||||
|
||||
int
|
||||
mappinginsert(op, key, value)
|
||||
register object *op;
|
||||
object *key;
|
||||
object *value;
|
||||
{
|
||||
register mappingobject *mp;
|
||||
register long hash;
|
||||
if (!is_mappingobject(op)) {
|
||||
err_badcall();
|
||||
return -1;
|
||||
}
|
||||
hash = hashobject(key);
|
||||
if (hash == -1)
|
||||
return -1;
|
||||
mp = (mappingobject *)op;
|
||||
/* if fill >= 2/3 size, resize */
|
||||
if (mp->ma_fill*3 >= mp->ma_size*2) {
|
||||
if (mappingresize(mp) != 0) {
|
||||
if (mp->ma_fill+1 > mp->ma_size)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
INCREF(value);
|
||||
INCREF(key);
|
||||
insertmapping(mp, key, hash, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
mappingremove(op, key)
|
||||
object *op;
|
||||
object *key;
|
||||
{
|
||||
register mappingobject *mp;
|
||||
register long hash;
|
||||
register mappingentry *ep;
|
||||
if (!is_mappingobject(op)) {
|
||||
err_badcall();
|
||||
return -1;
|
||||
}
|
||||
hash = hashobject(key);
|
||||
if (hash == -1)
|
||||
return -1;
|
||||
mp = (mappingobject *)op;
|
||||
ep = lookmapping(mp, key, hash);
|
||||
if (ep->me_value == NULL) {
|
||||
err_setval(KeyError, key);
|
||||
return -1;
|
||||
}
|
||||
DECREF(ep->me_key);
|
||||
INCREF(dummy);
|
||||
ep->me_key = dummy;
|
||||
DECREF(ep->me_value);
|
||||
ep->me_value = NULL;
|
||||
mp->ma_used--;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
mappingclear(op)
|
||||
object *op;
|
||||
{
|
||||
int i;
|
||||
register mappingobject *mp;
|
||||
if (!is_mappingobject(op))
|
||||
return;
|
||||
mp = (mappingobject *)op;
|
||||
for (i = 0; i < mp->ma_size; i++) {
|
||||
XDECREF(mp->ma_table[i].me_key);
|
||||
XDECREF(mp->ma_table[i].me_value);
|
||||
mp->ma_table[i].me_key = NULL;
|
||||
mp->ma_table[i].me_value = NULL;
|
||||
}
|
||||
mp->ma_used = 0;
|
||||
}
|
||||
|
||||
int
|
||||
mappinggetnext(op, ppos, pkey, pvalue)
|
||||
object *op;
|
||||
int *ppos;
|
||||
object **pkey;
|
||||
object **pvalue;
|
||||
{
|
||||
int i;
|
||||
register mappingobject *mp;
|
||||
if (!is_dictobject(op))
|
||||
return 0;
|
||||
mp = (mappingobject *)op;
|
||||
i = *ppos;
|
||||
if (i < 0)
|
||||
return 0;
|
||||
while (i < mp->ma_size && mp->ma_table[i].me_value == NULL)
|
||||
i++;
|
||||
*ppos = i+1;
|
||||
if (i >= mp->ma_size)
|
||||
return 0;
|
||||
if (pkey)
|
||||
*pkey = mp->ma_table[i].me_key;
|
||||
if (pvalue)
|
||||
*pvalue = mp->ma_table[i].me_value;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Methods */
|
||||
|
||||
static void
|
||||
mapping_dealloc(mp)
|
||||
register mappingobject *mp;
|
||||
{
|
||||
register int i;
|
||||
register mappingentry *ep;
|
||||
for (i = 0, ep = mp->ma_table; i < mp->ma_size; i++, ep++) {
|
||||
if (ep->me_key != NULL)
|
||||
DECREF(ep->me_key);
|
||||
if (ep->me_value != NULL)
|
||||
DECREF(ep->me_value);
|
||||
}
|
||||
if (mp->ma_table != NULL)
|
||||
DEL(mp->ma_table);
|
||||
DEL(mp);
|
||||
}
|
||||
|
||||
static int
|
||||
mapping_print(mp, fp, flags)
|
||||
register mappingobject *mp;
|
||||
register FILE *fp;
|
||||
register int flags;
|
||||
{
|
||||
register int i;
|
||||
register int any;
|
||||
register mappingentry *ep;
|
||||
fprintf(fp, "{");
|
||||
any = 0;
|
||||
for (i = 0, ep = mp->ma_table; i < mp->ma_size; i++, ep++) {
|
||||
if (ep->me_value != NULL) {
|
||||
if (any++ > 0)
|
||||
fprintf(fp, ", ");
|
||||
if (printobject((object *)ep->me_key, fp, flags) != 0)
|
||||
return -1;
|
||||
fprintf(fp, ": ");
|
||||
if (printobject(ep->me_value, fp, flags) != 0)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
fprintf(fp, "}");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
js(pv, w)
|
||||
object **pv;
|
||||
object *w;
|
||||
{
|
||||
joinstring(pv, w);
|
||||
XDECREF(w);
|
||||
}
|
||||
|
||||
static object *
|
||||
mapping_repr(mp)
|
||||
mappingobject *mp;
|
||||
{
|
||||
auto object *v;
|
||||
object *sepa, *colon;
|
||||
register int i;
|
||||
register int any;
|
||||
register mappingentry *ep;
|
||||
v = newstringobject("{");
|
||||
sepa = newstringobject(", ");
|
||||
colon = newstringobject(": ");
|
||||
any = 0;
|
||||
for (i = 0, ep = mp->ma_table; i < mp->ma_size; i++, ep++) {
|
||||
if (ep->me_value != NULL) {
|
||||
if (any++)
|
||||
joinstring(&v, sepa);
|
||||
js(&v, reprobject(ep->me_key));
|
||||
joinstring(&v, colon);
|
||||
js(&v, reprobject(ep->me_value));
|
||||
}
|
||||
}
|
||||
js(&v, newstringobject("}"));
|
||||
XDECREF(sepa);
|
||||
XDECREF(colon);
|
||||
return v;
|
||||
}
|
||||
|
||||
static int
|
||||
mapping_length(mp)
|
||||
mappingobject *mp;
|
||||
{
|
||||
return mp->ma_used;
|
||||
}
|
||||
|
||||
static object *
|
||||
mapping_subscript(mp, key)
|
||||
mappingobject *mp;
|
||||
register object *key;
|
||||
{
|
||||
object *v;
|
||||
long hash = hashobject(key);
|
||||
if (hash == -1)
|
||||
return NULL;
|
||||
v = lookmapping(mp, key, hash) -> me_value;
|
||||
if (v == NULL)
|
||||
err_setval(KeyError, key);
|
||||
else
|
||||
INCREF(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
static int
|
||||
mapping_ass_sub(mp, v, w)
|
||||
mappingobject *mp;
|
||||
object *v, *w;
|
||||
{
|
||||
if (w == NULL)
|
||||
return mappingremove((object *)mp, v);
|
||||
else
|
||||
return mappinginsert((object *)mp, v, w);
|
||||
}
|
||||
|
||||
static mapping_methods mapping_as_mapping = {
|
||||
mapping_length, /*mp_length*/
|
||||
mapping_subscript, /*mp_subscript*/
|
||||
mapping_ass_sub, /*mp_ass_subscript*/
|
||||
};
|
||||
|
||||
static object *
|
||||
mapping_keys(mp, args)
|
||||
register mappingobject *mp;
|
||||
object *args;
|
||||
{
|
||||
register object *v;
|
||||
register int i, j;
|
||||
if (!getnoarg(args))
|
||||
return NULL;
|
||||
v = newlistobject(mp->ma_used);
|
||||
if (v == NULL)
|
||||
return NULL;
|
||||
for (i = 0, j = 0; i < mp->ma_size; i++) {
|
||||
if (mp->ma_table[i].me_value != NULL) {
|
||||
object *key = mp->ma_table[i].me_key;
|
||||
INCREF(key);
|
||||
setlistitem(v, j, key);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
static object *
|
||||
mapping_values(mp, args)
|
||||
register mappingobject *mp;
|
||||
object *args;
|
||||
{
|
||||
register object *v;
|
||||
register int i, j;
|
||||
if (!getnoarg(args))
|
||||
return NULL;
|
||||
v = newlistobject(mp->ma_used);
|
||||
if (v == NULL)
|
||||
return NULL;
|
||||
for (i = 0, j = 0; i < mp->ma_size; i++) {
|
||||
if (mp->ma_table[i].me_value != NULL) {
|
||||
object *value = mp->ma_table[i].me_value;
|
||||
INCREF(value);
|
||||
setlistitem(v, j, value);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
static object *
|
||||
mapping_items(mp, args)
|
||||
register mappingobject *mp;
|
||||
object *args;
|
||||
{
|
||||
register object *v;
|
||||
register int i, j;
|
||||
if (!getnoarg(args))
|
||||
return NULL;
|
||||
v = newlistobject(mp->ma_used);
|
||||
if (v == NULL)
|
||||
return NULL;
|
||||
for (i = 0, j = 0; i < mp->ma_size; i++) {
|
||||
if (mp->ma_table[i].me_value != NULL) {
|
||||
object *key = mp->ma_table[i].me_key;
|
||||
object *value = mp->ma_table[i].me_value;
|
||||
object *item = newtupleobject(2);
|
||||
if (item == NULL) {
|
||||
DECREF(v);
|
||||
return NULL;
|
||||
}
|
||||
INCREF(key);
|
||||
settupleitem(item, 0, key);
|
||||
INCREF(value);
|
||||
settupleitem(item, 1, value);
|
||||
setlistitem(v, j, item);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
object *
|
||||
getmappingkeys(mp)
|
||||
object *mp;
|
||||
{
|
||||
if (mp == NULL || !is_mappingobject(mp)) {
|
||||
err_badcall();
|
||||
return NULL;
|
||||
}
|
||||
return mapping_keys((mappingobject *)mp, (object *)NULL);
|
||||
}
|
||||
|
||||
object *
|
||||
getmappingvalues(mp)
|
||||
object *mp;
|
||||
{
|
||||
if (mp == NULL || !is_mappingobject(mp)) {
|
||||
err_badcall();
|
||||
return NULL;
|
||||
}
|
||||
return mapping_values((mappingobject *)mp, (object *)NULL);
|
||||
}
|
||||
|
||||
object *
|
||||
getmappingitems(mp)
|
||||
object *mp;
|
||||
{
|
||||
if (mp == NULL || !is_mappingobject(mp)) {
|
||||
err_badcall();
|
||||
return NULL;
|
||||
}
|
||||
return mapping_values((mappingobject *)mp, (object *)NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
mapping_compare(a, b)
|
||||
mappingobject *a, *b;
|
||||
{
|
||||
object *akeys, *bkeys;
|
||||
int i, n, res;
|
||||
if (a == b)
|
||||
return 0;
|
||||
if (a->ma_used == 0) {
|
||||
if (b->ma_used != 0)
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
if (b->ma_used == 0)
|
||||
return 1;
|
||||
}
|
||||
akeys = mapping_keys(a, (object *)NULL);
|
||||
bkeys = mapping_keys(b, (object *)NULL);
|
||||
if (akeys == NULL || bkeys == NULL) {
|
||||
/* Oops, out of memory -- what to do? */
|
||||
/* For now, sort on address! */
|
||||
XDECREF(akeys);
|
||||
XDECREF(bkeys);
|
||||
if (a < b)
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
sortlist(akeys);
|
||||
sortlist(bkeys);
|
||||
n = a->ma_used < b->ma_used ? a->ma_used : b->ma_used; /* smallest */
|
||||
res = 0;
|
||||
for (i = 0; i < n; i++) {
|
||||
object *akey, *bkey, *aval, *bval;
|
||||
long ahash, bhash;
|
||||
akey = getlistitem(akeys, i);
|
||||
bkey = getlistitem(bkeys, i);
|
||||
res = cmpobject(akey, bkey);
|
||||
if (res != 0)
|
||||
break;
|
||||
ahash = hashobject(akey);
|
||||
if (ahash == -1)
|
||||
err_clear(); /* Don't want errors here */
|
||||
bhash = hashobject(bkey);
|
||||
if (bhash == -1)
|
||||
err_clear(); /* Don't want errors here */
|
||||
aval = lookmapping(a, akey, ahash) -> me_value;
|
||||
bval = lookmapping(b, bkey, bhash) -> me_value;
|
||||
res = cmpobject(aval, bval);
|
||||
if (res != 0)
|
||||
break;
|
||||
}
|
||||
if (res == 0) {
|
||||
if (a->ma_used < b->ma_used)
|
||||
res = -1;
|
||||
else if (a->ma_used > b->ma_used)
|
||||
res = 1;
|
||||
}
|
||||
DECREF(akeys);
|
||||
DECREF(bkeys);
|
||||
return res;
|
||||
}
|
||||
|
||||
static object *
|
||||
mapping_has_key(mp, args)
|
||||
register mappingobject *mp;
|
||||
object *args;
|
||||
{
|
||||
object *key;
|
||||
long hash;
|
||||
register long ok;
|
||||
if (!getargs(args, "O", &key))
|
||||
return NULL;
|
||||
hash = hashobject(key);
|
||||
if (hash == -1)
|
||||
return NULL;
|
||||
ok = lookmapping(mp, key, hash)->me_value != NULL;
|
||||
return newintobject(ok);
|
||||
}
|
||||
|
||||
static struct methodlist mapp_methods[] = {
|
||||
{"has_key", mapping_has_key},
|
||||
{"items", mapping_items},
|
||||
{"keys", mapping_keys},
|
||||
{"values", mapping_values},
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static object *
|
||||
mapping_getattr(mp, name)
|
||||
mappingobject *mp;
|
||||
char *name;
|
||||
{
|
||||
return findmethod(mapp_methods, (object *)mp, name);
|
||||
}
|
||||
|
||||
typeobject Mappingtype = {
|
||||
OB_HEAD_INIT(&Typetype)
|
||||
0,
|
||||
"dictionary",
|
||||
sizeof(mappingobject),
|
||||
0,
|
||||
mapping_dealloc, /*tp_dealloc*/
|
||||
mapping_print, /*tp_print*/
|
||||
mapping_getattr, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
mapping_compare, /*tp_compare*/
|
||||
mapping_repr, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
&mapping_as_mapping, /*tp_as_mapping*/
|
||||
};
|
||||
|
||||
/* For backward compatibility with old dictionary interface */
|
||||
|
||||
static object *last_name_object;
|
||||
static char *last_name_char;
|
||||
|
||||
object *
|
||||
getattro(v, name)
|
||||
object *v;
|
||||
object *name;
|
||||
{
|
||||
if (name != last_name_object) {
|
||||
XDECREF(last_name_object);
|
||||
INCREF(name);
|
||||
last_name_object = name;
|
||||
last_name_char = getstringvalue(name);
|
||||
}
|
||||
return getattr(v, last_name_char);
|
||||
}
|
||||
|
||||
int
|
||||
setattro(v, name, value)
|
||||
object *v;
|
||||
object *name;
|
||||
object *value;
|
||||
{
|
||||
if (name != last_name_object) {
|
||||
XDECREF(last_name_object);
|
||||
INCREF(name);
|
||||
last_name_object = name;
|
||||
last_name_char = getstringvalue(name);
|
||||
}
|
||||
return setattr(v, last_name_char, value);
|
||||
}
|
||||
|
||||
object *
|
||||
dictlookup(v, key)
|
||||
object *v;
|
||||
char *key;
|
||||
{
|
||||
if (key != last_name_char) {
|
||||
XDECREF(last_name_object);
|
||||
last_name_object = newstringobject(key);
|
||||
if (last_name_object == NULL) {
|
||||
last_name_char = NULL;
|
||||
return NULL;
|
||||
}
|
||||
last_name_char = key;
|
||||
}
|
||||
return mappinglookup(v, last_name_object);
|
||||
}
|
||||
|
||||
int
|
||||
dictinsert(v, key, item)
|
||||
object *v;
|
||||
char *key;
|
||||
object *item;
|
||||
{
|
||||
if (key != last_name_char) {
|
||||
XDECREF(last_name_object);
|
||||
last_name_object = newstringobject(key);
|
||||
if (last_name_object == NULL) {
|
||||
last_name_char = NULL;
|
||||
return -1;
|
||||
}
|
||||
last_name_char = key;
|
||||
}
|
||||
return mappinginsert(v, last_name_object, item);
|
||||
}
|
||||
|
||||
int
|
||||
dictremove(v, key)
|
||||
object *v;
|
||||
char *key;
|
||||
{
|
||||
if (key != last_name_char) {
|
||||
XDECREF(last_name_object);
|
||||
last_name_object = newstringobject(key);
|
||||
if (last_name_object == NULL) {
|
||||
last_name_char = NULL;
|
||||
return -1;
|
||||
}
|
||||
last_name_char = key;
|
||||
}
|
||||
return mappingremove(v, last_name_object);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user