1 / 47
Sep 2004

I got rid of the error (by using "try: except:") but got WA instead.

Incorrect input data? But why? Otherwise I'm not able (in principle) to guess what sort of input data (or its format) can cause my code to stumble upon it...

  • created

    Sep '04
  • last reply

    Sep '15
  • 46

    replies

  • 2.3k

    views

  • 30

    users

  • 1

    link

My home testing:

1 5
120
2 5 6
120
720
1 100
93326215443944152681699238856266700490715968264381621468592963
89521759999322991560894146397615651828625369792082722375825118
5210916864000000000000000000000000

Hello,

Indeed, your program works fine if the input is 1|space|5, but not if it is 1|newline|5.

Adrian,
but this works fine too:

f=open('D:/m.txt')
s=f.read().split()
f.close()
for i in xrange(2,long(s[0])+2): 
    j=1; q=1
    while j<long(s[i-1]):
        j+=1; q=q*j
    print q

In m.txt these 4 lines (no any spaces):

3
3
4
100

I mean for the split() method there is no difference between spaces and newlines.

Well, it does make a difference to your program. We are using Python 2.3.4 (#2, Jul 5 2004, 09:15:05).

Try something like this: echo -e "1\n5\n" | python program.py

Thanks, Adrian. I will try it.

BTW, ver. 2.3.4. seems works much slower than e.g. ver. 2.2.1.

I mean Windows versions.

LOL I failed again.

s=raw_input()
s=s.split('\\n') 
for i in xrange(2,long(s[0])+2): 
    j=1; q=1 
    while j<long(s[i-1]): 
        j+=1; q=q*j 
    print q

3\n5\n2\n100\n

works fine for me. Seems I have to quit.

Alternatively, you could try:

count = input()
for eachCase in range(count):
    ....

Adrian,

I much appreciate your kind replies but I really can't understand

what's going on. I think my brains are too straightforward.

I don't really know Python, but I believe I know what's the problem:
For s.split() whitespaces don't seem to matter indeed, but newline chars do matter for raw_input().
Your raw_input() reads only the first number from input data and it causes the program to crash.

well, guys. This is one of the greatest lols I ever met.

count=input()
for i in xrange(count): 
    next=input()
    j=1; q=1 
    while j<next: 
        j+=1; q=q*j 
    print q,'asdfgh'

Now I put values in one by one and pressing [Enter]:

3
5
120 asdfgh
6
720 asdfgh
7
5040 asdfgh
33
33

"For" cycle is executed only 3 times and that's ok. But why Py shell
then waits for one more input value (33) and then echoes it without
asking and only after that it terminates the code execution...
it's above my head (maybe irreversibly damaged by VB).

[quote="ZZZ"]

(snipped)

[/quote]
Well, this code does work, when you put an EOF at end of the list.
I got AC with it (without "as...", of course), see solution 8363.

2 years later
10 days later

Hmm tez mam problem, tzn ja dostaje WA, ma ktoś może jakieś wredne testy, bo szczerze to nie wiem co może być nie tak...

t to zapewne liczba testów a n liczba liczb w tescie
nie jest to jednak podane w tresci zadania

P.S mój AC ma t i n <= 2^31

Właśnie męczę się z tym zadaniem, ale cały czas mam TLE.
Czy mógłby ktoś mi powiedzieć co w moim rozwiązaniu jest nie tak?

#include<stdio.h>
#include<list>
#include<queue>
#include<stack>
#define MAXN 1002
using namespace std;
class Graf{
      private:
         int n,nrGrafu;
         bool odwiedzony[MAXN];
         list<int> graf[MAXN];
         queue<int> kol;
         void DFS(int start);
         void BFS(int start);
      public:
         Graf(int nr);
         void obsluz();    
      };
Graf::Graf(int nr){
    nrGrafu=nr;           
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
            int m,o,t;
            scanf("%d %d",&o,&m);
             for(int j=0;j<m;j++)  
                    {
                    scanf("%d",&t);
                    graf[o].push_back(t);            
                    };
            };    
     };
 void Graf::obsluz(){
       printf("graph %d\n", nrGrafu);      
       while(1){
                int typ, sta;
                scanf("%d %d",&sta, &typ);
                if( sta == 0) break; 
                for(int i=0; i<=n; i++) odwiedzony[i]=false;
                if (typ==0)  DFS(sta);
                if (typ==1)  BFS(sta);
                printf("\n");  
       };  
      };
void Graf::DFS(int i)
{
odwiedzony[i]=true;
printf("%d ",i);
for(list<int>::iterator k=graf[i].begin(); k!=graf[i].end();k++)
		if(odwiedzony[*k]==false) DFS(*k);
};
void Graf::BFS(int start){
    kol.push(start);
    bool odwiedzony[n+1];
    for(int i=0; i<=n; i++) odwiedzony[i]=false;
    odwiedzony[start]=true;
    while(!kol.empty()){
    printf("%d ", kol.front());
    list<int>::iterator i;
    for(i=graf[kol.front()].begin(); i != graf[kol.front()].end(); ++i){ 
                                     if(!odwiedzony[*i]) kol.push(*i);
                                      odwiedzony[*i]=true; };
    kol.pop();
    };
};
int main(){
int d;
scanf("%d", &d);
for(int nrGr=1;nrGr<=d;nrGr++){
        Graf grafik(nrGr);
        grafik.obsluz();
       };
return 0;  
};
1 year later

No ale skąd ty bierzesz zmienną "t" ? Przecież w tym zadaniu nie ma na początku liczby oznaczającej ilość zestawów danych.

2 months later

takie rozwiązanie powinno przejść. tylko nie podoba mi się ta pętla

while(1)
{...}

czy Ci to zawsze działało jeśli ilość danych wejściowych była nieokreślona?
i po co dwa razy w pętli cin.eof()?