#include <stdio.h>
int func1()
{
return 5;
}
int func2(int x)
{
return x * 2;
}
int func3(int x)
{
return x * 3 + 1;
}
int main(void)
{
printf("%d\n", func3(func2(func1())));
return 0;
}
[guest@localhost c]$ .ansi t.c -o t
[guest@localhost c]$ ./t
31
[guest@localhost c]$
>>> def f(seq):
... m1 = m2 = None
... for i in seq:
... if m2 is None:
... m2 = i
... elif m1 is None:
... if i > m2:
... m1, m2 = m2, i
... else:
... m1 = i
... elif i > m2:
... m1, m2 = m2, i
... elif i > m1:
... m1 = i
... return (m1, m2)
...
>>> a = [1, 2, 39, 4, 13, 4, 5, 6, 7, 3, 23, 2]
>>>
>>> f(a)
(23, 39)
>>>
>>> def f(d):
... for i in set(d):
... e = d[i]
... if isinstance(e, dict):
... f(e)
... elif e == 0:
... del d[i]
...
>>> d = {'user1': {'var1': 2,
... 'var2': 0,
... 'var3': 1,
... 'var4': 0},
... 'user2': {'var1': 0,
... 'var2': 1,
... 'var3': 0,
... 'var4': 0},
... 'user3': {'var1': 1,
... 'var2': 0,
... 'var3': 0,
... 'var4': 0}}
>>>
>>> f(d)
>>> d
{'user3': {'var1': 1}, 'user2': {'var2': 1}, 'user1': {'var1': 2, 'var3': 1}}
>>>
#include <stdio.h>
#include <ctype.h>
int main(void)
{
int c, wassp;
wassp = 1;
while ((c = getchar()) != EOF) {
if (isspace(c))
wassp = 1;
else if (wassp) {
wassp = 0;
putchar(c);
}
}
putchar('\n');
return 0;
}
[guest@localhost c]$ .ansi t.c -o t
[guest@localhost c]$ echo "abcd efgh ijkl" | ./t
aei
[guest@localhost c]$
Как с помощью рекурсии удалить последний элемент списка?
rx = r'\. %s (.+\n)+[}]'% clss
Хотелось бы услышать ваше мнение, сложно ли будет перейти с C# на С++, так сказать цену вопроса.
<img
".span>
".>>> import lxml.etree
>>>
>>> text = """\
... <eventsList>
... <event>
... <id>374648e7-0c33-403f-bec5-c580fcf9fc8b</id>
... <date>2016-03-30T21:11:33.163+03:00</date>
... <type>deletedPrintedItems</type>
... <departmentId>3</departmentId>
... <attribute>
... <name>comment</name>
... <value>sadasd</value>
... </attribute>
... <attribute>
... <name>user</name>
... <value>65d90cba-a421-4e4d-9d3e-14ddd6907280</value>
... </attribute>
... <attribute>
... <name>openTime</name>
... <value>Wed Mar 30 21:07:53 MSK 2016</value>
... </attribute>
... <attribute>
... <name>tableNum</name>
... <value>2</value>
... </attribute>
... <attribute>
... <name>session</name>
... <value>1.000000000</value>
... </attribute>
... <attribute>
... <name>orderNum</name>
... <value>4.000000000</value>
... </attribute>
... <attribute>
... <name>reason</name>
... <value>Со списанием</value>
... </attribute>
... <attribute>
... <name>receiptsSum</name>
... <value>0E-9</value>
... </attribute>
... <attribute>
... <name>dishes</name>
... <value>Салат Оливье</value>
... </attribute>
... <attribute>
... <name>isBanquet</name>
... <value>0E-9</value>
... </attribute>
... <attribute>
... <name>withWriteoff</name>
... <value>1.000000000</value>
... </attribute>
... <attribute>
... <name>penalty</name>
... <value>0E-9</value>
... </attribute>
... <attribute>
... <name>rowCount</name>
... <value>1.000000000</value>
... </attribute>
... <attribute>
... <name>numGuests</name>
... <value>4.000000000</value>
... </attribute>
... <attribute>
... <name>auth</name>
... <value>65d90cba-a421-4e4d-9d3e-14ddd6907280</value>
... </attribute>
... <attribute>
... <name>orderSumAfterDiscount</name>
... <value>0E-9</value>
... </attribute>
... <attribute>
... <name>terminal</name>
... <value>49c7d0ba-a469-517f-0153-61a7bcb29ccb</value>
... </attribute>
... <attribute>
... <name>sum</name>
... <value>70.000000000</value>
... </attribute>
... <attribute>
... <name>method</name>
... <value>Списание за счет заведения</value>
... </attribute>
... <attribute>
... <name>orderId</name>
... <value>e55c392f-ea8a-4c96-aecd-2bd0b6ffd2cd</value>
... </attribute>
... <attribute>
... <name>waiter</name>
... <value>5daf4283-ae8c-4a95-83e5-052fb4a33570</value>
... </attribute>
... </event>
... <event>
... <id>61d3cb56-74dd-4d20-86ae-217c37f15f01</id>
... <date>2016-03-30T21:11:41.090+03:00</date>
... <type>frontLogout</type>
... <departmentId>3</departmentId>
... <attribute>
... <name>user</name>
... <value>65d90cba-a421-4e4d-9d3e-14ddd6907280</value>
... </attribute>
... <attribute>
... <name>session</name>
... <value>1.000000000</value>
... </attribute>
... <attribute>
... <name>terminal</name>
... <value>49c7d0ba-a469-517f-0153-61a7bcb29ccb</value>
... </attribute>
... </event>
... </eventsList>
... """
>>>
>>> doc = lxml.etree.fromstring(text)
>>> events = doc.xpath(r'//event/type[text() = "deletedPrintedItems"]/..')
>>>
>>> for event in events:
... comments = event.xpath(r'.//attribute/name[text() = "comment"]'
... r'/../value/text()')
... print(comments)
...
['sadasd']
>>>
>>> class UnorderedList:
... def __init__(self):
... self.head = None
...
... def append(self, item):
... newnode = Node(item)
... if self.head is None:
... self.head = newnode
... return
... current = self.head
... while True:
... nextnode = current.getNext()
... if nextnode is None:
... break
... current = nextnode
... current.setNext(newnode)
...
... def print(self):
... current = self.head
... while current is not None:
... print(current.getData(), end=' ')
... current = current.getNext()
... print()
...
>>> class Node:
... def __init__(self, data):
... self.data = data
... self.next = None
...
... def getData(self):
... return self.data
...
... def getNext(self):
... return self.next
...
... def setData(self, data):
... self.data = data
...
... def setNext(self, node):
... self.next = node
...
>>> lst = UnorderedList()
>>> lst.append(1)
>>> lst.append(2)
>>> lst.append(3)
>>> lst.print()
1 2 3
>>>
Цель моей задачи овладеть макросами