____  ___    _  _     _   _ _____     _______
 / ___|/ _ \  | || |   | | | |_ _\ \   / / ____|
| |  _| | | | | || |_  | |_| || | \ \ / /|  _|
| |_| | |_| | |__   _| |  _  || |  \ V / | |___
 \____|\___/     |_|   |_| |_|___|  \_/  |_____|

 --- A GOPHER-LIKE INTERFACE FOR HIVE BLOCKCHAIN ---

python3刷TK题库 1011: 软件版本

BY: @spearous | CREATED: Jan. 17, 2018, 1:14 a.m. | VOTES: 1 | PAYOUT: $0.00 | [ VOTE ]

这又是多重判断选择问题,算是练一练条件判断的使用吧。python3有几种条件判断格式语句,并且可以嵌套:

if statement1:                  #outer if 
    print("hello world")

    if nested_statement1:       #first nested if 
        print("yes")

    elif nested_statement2:     #first nested elif
        print("maybe")

    else:                       #first nested else
        print("no")

elif statement2:                #outer elif
    print("hello galaxy")

    if nested_statement3:       #second nested if
        print("yes")

    elif nested_statement4:     #second nested elif
        print("maybe")

    else:                       #second nested else
        print("no")

else:                           #outer else
    statement("hello universe")

而逻辑关系运算符有:

Operator What it means == Equal to != Not equal to < Less than > Greater than <= Less than or equal to >= Greater than or equal to and True only if both are true or True if at least one is true not True only if false

http://tk.hustoj.com/problem.php?id=1011

1011: 软件版本
时间限制: 1 Sec 内存限制: 32 MB
提交: 3321 解决: 1561
[提交][状态][讨论版][命题人:外部导入][下载1元][20kb]
题目描述
相信大家一定有过在网上下载软件而碰到多个不同版本的情况。一般来说,软件的版本号由三个部分组成,主版本号(Major Version Number),子版本号(Minor Version Number)和修订号(Revision_Number)。当软件进行了重大的修改时,主版本号加一;当软件在原有基础上增加部分功能时,主版本号不变,子版本号加一;当软件仅仅修正了部分bug时,主版本号和子版本号都不变,修正号加一。
在我们比较软件的两个版本的新旧时,都是先比较主版本号,当主版本号相同时再比较子版本号,前两者都相同的情况下再比较修正号。版本号越大的软件越新。
现在,小明在下载软件的时候碰到了两个版本,请你告诉他哪个版本更新一些。
输入
输入的第一行有一个整数T,代表有T组测试。接下来有T组测试。
每组测试分两行,第一行有三个整数代表第一个软件版本的主版本号,子版本号和修订号。第二行也有三个整数代表第二个软件版本的主版本号,子版本号和修订号。
数据中出现的整数都在[0,1000]范围之内。
输出
对于每组测试,如果第一个软件的版本新点,请输出First,如果第二个软件的版本新点,请输出Second,否则输出Same。
样例输入
3
1 1 0
1 1 1
1 1 1
1 1 0
1 1 1
1 1 1
样例输出
Second
First
Same

我的python3程序:

Number_of_test=int(input())
for i in range(0,Number_of_test):
    data_of_first=input()
    data_of_second=input()
    if data_of_first.split()[0] &gt; data_of_second.split()[0]:
        print("First")
    elif data_of_first.split()[0] &lt; data_of_second.split()[0]:
        print("Second")
    elif data_of_first.split()[0] == data_of_second.split()[0]:
        if data_of_first.split()[1] &gt; data_of_second.split()[1]:
            print("First")
        elif data_of_first.split()[1] &lt; data_of_second.split()[1]:
            print("Second")
        elif data_of_first.split()[1] == data_of_second.split()[1]:
            if data_of_first.split()[2] &gt; data_of_second.split()[2]:
                print("First")
            elif data_of_first.split()[2] &lt; data_of_second.split()[2]:
                print("Second")
            elif data_of_first.split()[2] == data_of_second.split()[2]:
                print("Same")

C

#include//用数组做也行
main()
{
    int t;
    int a[3],b[3];
    int i;
    scanf("%d",&amp;t);
    while(t--)
    {
        scanf("%d%d%d",&amp;a[0],&amp;a[1],&amp;a[2]);
        scanf("%d%d%d",&amp;b[0],&amp;b[1],&amp;b[2]);
        for(i=0;i&lt;3;i++)
        {
            if(a[i]&gt;b[i])
            {
                printf("First\n");
                break;
            }
            else
            {
                if(a[i]  

using namespace std;  

int main()  
{  
    int n;  
    cin&gt;&gt;n;  
    while(n--)  
    {  
        int a[6];  
        for(int i=0;i&lt;6;++i)  
        {  
            cin&gt;&gt;a[i];  
        }  
        if(a[0]a[3] || ((a[0]==a[3]) &amp;&amp; (a[1]&gt;a[2])) || ((a[0]==a[3])&amp;&amp;(a[1]==a[4]) &amp;&amp;(a[2]&gt;a[5])))  
            cout&lt;&lt;"First"&lt;&lt;endl;  
        else  
            cout&lt;&lt;"Same"&lt;&lt;endl;  
    }  
    return 0;  
}  

参考资料:
1. https://www.digitalocean.com/community/tutorials/how-to-write-conditional-statements-in-python-3-2
2. https://www.digitalocean.com/community/tutorials/understanding-boolean-logic-in-python-3
3. http://www.tk4479.net/u013041792/article/details/17123883
4. http://blog.csdn.net/AdamChinaren/article/details/18925505

TAGS: [ #acm ] [ #cn ] [ #cn-reader ] [ #tk ] [ #python ]

Replies

NO REPLIES FOUND.

[ BACK TO TRENDING ] [ BACK TO MENU ]
CMD>