#7365: 一直TLE 有辦法改善嗎??


sam574 (liu)

學校 : 國立中興大學
編號 : 15117
來源 : [140.120.15.252]
最後登入時間 :
2014-02-11 16:18:00
a020. 身分證檢驗 | From: [60.244.184.218] | 發表日期 : 2013-01-03 18:08

執行一直逾時 是哪裡花了比較多時間 有其他的方法嗎

謝謝

======================================== 

#include <stdio.h>
#include <stdlib.h>

void main(void)
{
    char string1[10];

    while(scanf("%s",&string1))
    {
        int Letter=0,num=0,i=1,j=8;

        switch(string1[0])
        {
            case 'A':
                Letter=10;
                break;
            case 'B':
                Letter=11;
                break;
            case 'C':
                Letter=12;
                break;
            case 'D':
                Letter=13;
                break;
            case 'E':
                Letter=14;
                break;
            case 'F':
                Letter=15;
                break;
            case 'G':
                Letter=16;
                break;
            case 'H':
                Letter=17;
                break;
            case 'I':
                Letter=34;
                break;
            case 'J':
                Letter=18;
                break;
            case 'K':
                Letter=19;
                break;
            case 'L':
                Letter=20;
                break;
            case 'M':
                Letter=21;
                break;
            case 'N':
                Letter=22;
                break;
            case 'O':
                Letter=35;
                break;
            case 'P':
                Letter=23;
                break;
            case 'Q':
                Letter=24;
                break;
            case 'R':
                Letter=25;
                break;
            case 'S':
                Letter=26;
                break;
            case 'T':
                Letter=27;
                break;
            case 'U':
                Letter=28;
                break;
            case 'V':
                Letter=29;
                break;
            case 'W':
                Letter=32;
                break;
            case 'X':
                Letter=30;
                break;
            case 'Y':
                Letter=31;
                break;
            case 'Z':
                Letter=33;
                break;
        }

        num= Letter/10 + (Letter%10)*9;
        for(i;i<9;i++)
        {
            num=num+(string1[i]-48)*j;
            j--;
        }
        num=num+string1[9]-48;

        if(num%10==0)
        printf("real\n");
        else
        printf("fake\n");
    }
}

 
#7366: Re:一直TLE 有辦法改善嗎??


passerr (20130326 0340 48)

學校 : 不指定學校
編號 : 8516
來源 : [125.224.93.117]
最後登入時間 :
2024-09-05 12:09:52
a020. 身分證檢驗 | From: [36.235.234.22] | 發表日期 : 2013-01-03 19:26

執行一直逾時 是哪裡花了比較多時間 有其他的方法嗎

謝謝

======================================== 

#include
#include

void main(void)
{
    char string1[10];

    while(scanf("%s",&string1))
    {
        int Letter=0,num=0,i=1,j=8;

        switch(string1[0])
        {
            case 'A':
                Letter=10;
                break;
            case 'B':
                Letter=11;
                break;
            case 'C':
                Letter=12;
                break;
            case 'D':
                Letter=13;
                break;
            case 'E':
                Letter=14;
                break;
            case 'F':
                Letter=15;
                break;
            case 'G':
                Letter=16;
                break;
            case 'H':
                Letter=17;
                break;
            case 'I':
                Letter=34;
                break;
            case 'J':
                Letter=18;
                break;
            case 'K':
                Letter=19;
                break;
            case 'L':
                Letter=20;
                break;
            case 'M':
                Letter=21;
                break;
            case 'N':
                Letter=22;
                break;
            case 'O':
                Letter=35;
                break;
            case 'P':
                Letter=23;
                break;
            case 'Q':
                Letter=24;
                break;
            case 'R':
                Letter=25;
                break;
            case 'S':
                Letter=26;
                break;
            case 'T':
                Letter=27;
                break;
            case 'U':
                Letter=28;
                break;
            case 'V':
                Letter=29;
                break;
            case 'W':
                Letter=32;
                break;
            case 'X':
                Letter=30;
                break;
            case 'Y':
                Letter=31;
                break;
            case 'Z':
                Letter=33;
                break;
        }

        num= Letter/10 + (Letter%10)*9;
        for(i;i<9;i++)
        {
            num=num+(string1[i]-48)*j;
            j--;
        }
        num=num+string1[9]-48;

        if(num%10==0)
        printf("real\n");
        else
        printf("fake\n");
    }
}


嗯!你用什麼編譯器的?

這行應該會有警告的

while(scanf("%s",&string1))

你改這樣試試

 while(scanf("%s",string1)==1)

 
#7367: Re:一直TLE 有辦法改善嗎??


sam574 (liu)

學校 : 國立中興大學
編號 : 15117
來源 : [140.120.15.252]
最後登入時間 :
2014-02-11 16:18:00
a020. 身分證檢驗 | From: [60.244.184.218] | 發表日期 : 2013-01-03 20:22

執行一直逾時 是哪裡花了比較多時間 有其他的方法嗎

謝謝

======================================== 

#include
#include

void main(void)
{
    char string1[10];

    while(scanf("%s",&string1))
    {
        int Letter=0,num=0,i=1,j=8;

        switch(string1[0])
        {
            case 'A':
                Letter=10;
                break;
            case 'B':
                Letter=11;
                break;
            case 'C':
                Letter=12;
                break;
            case 'D':
                Letter=13;
                break;
            case 'E':
                Letter=14;
                break;
            case 'F':
                Letter=15;
                break;
            case 'G':
                Letter=16;
                break;
            case 'H':
                Letter=17;
                break;
            case 'I':
                Letter=34;
                break;
            case 'J':
                Letter=18;
                break;
            case 'K':
                Letter=19;
                break;
            case 'L':
                Letter=20;
                break;
            case 'M':
                Letter=21;
                break;
            case 'N':
                Letter=22;
                break;
            case 'O':
                Letter=35;
                break;
            case 'P':
                Letter=23;
                break;
            case 'Q':
                Letter=24;
                break;
            case 'R':
                Letter=25;
                break;
            case 'S':
                Letter=26;
                break;
            case 'T':
                Letter=27;
                break;
            case 'U':
                Letter=28;
                break;
            case 'V':
                Letter=29;
                break;
            case 'W':
                Letter=32;
                break;
            case 'X':
                Letter=30;
                break;
            case 'Y':
                Letter=31;
                break;
            case 'Z':
                Letter=33;
                break;
        }

        num= Letter/10 + (Letter%10)*9;
        for(i;i<9;i++)
        {
            num=num+(string1[i]-48)*j;
            j--;
        }
        num=num+string1[9]-48;

        if(num%10==0)
        printf("real\n");
        else
        printf("fake\n");
    }
}


嗯!你用什麼編譯器的?

這行應該會有警告的

while(scanf("%s",&string1))

你改這樣試試

 while(scanf("%s",string1)==1)


現在不會TLE了

但是換成RE... 是哪裡字串有錯嗎??

 
ZeroJudge Forum