Page 3 of 6
Re: Compile Error 10191
Posted: Mon Mar 21, 2005 4:21 pm
by misof
Ghust_omega wrote:I have Fedora 3 and g++ 3.4.2 I wish to know What are the flags for Compile under Linux
Sadly, as far as I know the judge still uses something like gcc 2.95.4, so it may happen that that the judge can't compile some code your compiler can. A notorious example is that the compiler at UVa doesn't support typeof().
The usual problem is that common (i.e. also your) g++ includes most of the STL libraries automatically, so if you forget an explicit #include, the code will still compile on your machine. The compiler the judge uses doesn't do this, thus the result is a compile error.
Posted: Mon Mar 21, 2005 4:53 pm
by sumankar
misof wrote:
Sumankar: I really don't understand what you are talking about. Both your points are wrong.
I had trouble, including both, though i am not sure if it was on linux or not, which is why i said
maybe.
Moreover, he IS using the namespace std!
All he is doing is pulluting the whole namespace.When all that you need are
two `std:: ' before vector and sort, why not type in the extra chars rather than pollute the whole namespace?
Suman.
P.S: C is not C++, they are different languages and just because we can shoot ourselves in the foot does not mean we should.
Posted: Mon Mar 21, 2005 11:05 pm
by Krzysztof Duleba
misof wrote:Sadly, as far as I know the judge still uses something like gcc 2.95.4, so it may happen that that the judge can't compile some code your compiler can. A notorious example is that the compiler at UVa doesn't support typeof().
It does, but it's called __typeof() and as __typeof it also works in newer versions of g++.
Posted: Tue Mar 22, 2005 12:29 am
by Ghust_omega
Thanks to sumankar,misof and Krzysztof Duleba for their quick answers,and advice I solve the problem and Get WA

but after somes tries AC

The problems was #include <algorithm>
Thanks In Adavance
TO sumankar,misof and Krzysztof Duleba KEEP POSTING !!
Posted: Tue Mar 22, 2005 2:39 am
by misof
sumankar wrote:misof wrote:
Moreover, he IS using the namespace std!
All he is doing is pulluting the whole namespace.When all that you need are
two `std:: ' before vector and sort, why not type in the extra chars rather than pollute the whole namespace?
Suman.
Okay, I understand your point now. The source of the misunderstanding between us is just that our philosophy on this point differs.
When writing a larger piece of code for a SW company your approach has its advantages, no doubt about that. But for a programming contest all the programs we write are "quick&dirty". Here I see no problems with simply using the whole namespace -- it makes my code a little bit shorter, easier to read and write, and it causes no problems. I'm still saying that (in a programming contest!) by including "using namespace std;" in your program you lose nothing. I'll keep on doing it.
If you have a "counter-example" or some other thoughts on this topic, I'll be more than glad to read them.
[Well, the only "problem" I can remember was when (on TopCoder) I had to write a method called sort()... it took me a while to realize that if I want to use the sort() from STL I have to refer to it as to std::sort() ... but in fact this is NOT a problem with the issue we were discussing

]
Posted: Tue Mar 22, 2005 6:42 am
by sumankar
misof wrote:
Okay, I understand your point now. The source of the misunderstanding between us is just that our philosophy on this point differs.
I am relieved

.
When writing a larger piece of code for a SW company your approach has its advantages, no doubt about that. But for a programming contest all the programs we write are "quick&dirty". Here I see no problems with simply using the whole namespace -- it makes my code a little bit shorter, easier to read and write, and it causes no problems. I'm still saying that (in a programming contest!) by including "using namespace std;" in your program you lose nothing.
My point, exactly.And I have a little more to add, when I was going home
yesterday, a little disturbed at having started what seemed like a holy flame war, I was thinking about quick & dirty hacks vs robust coding. I was unsure how important it was to code quick vs code correctly. And it took some time before I realised that even if it takes a little time, we should indulge in a little more robust coding - that helps later, if you start
running even before you can walk - you'll trip for sure.
I'll keep on doing it
The call is yours!
If you have a "counter-example" or some other thoughts on this topic, I'll be more than glad to read them.
None at this point of time

Posted: Tue Mar 22, 2005 6:55 am
by sumankar
One more thing, since programmers are _lazy_

, if std:: hurts try this
Code: Select all
typedef std::map<int, int> myMap;
That takes care of the `i can type five extra chars when coding' disease

Regards,
Suman.
10191-why all the time WA
Posted: Tue Aug 16, 2005 9:27 pm
by 59557RC
i think my code outputs correctly . but why WA? any1 pls help me?
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,k,n,m=0,t1[102],t2[102], max;
char time1[102][6],time2[102][6],app[256];
while(scanf("%d",&n)!=EOF){ max=0;
for(i=1;i<=n;i++) {scanf("%s %s",time1,time2);gets(app); }
strcpy(time2[0],"10:00");
strcpy(time1[n+1],"18:00");
for(i=0;i<=n+1;i++){
t1=((time1[0]-'0')*10+(time1[1]-'0'))*60+((time1[3]-'0')*10+(time1[4]-'0'));
t2=((time2[0]-'0')*10+(time2[1]-'0'))*60+((time2[i][3]-'0')*10+(time2[i][4]-'0'));
}
for(i=1;i<=n+1;i++){
k=t1[i]-t2[i-1];
if(k>max) {max=k;j=i-1;}
}
if(max/60==0) printf("Day #%d: the longest nap starts at %s and will last for %d minutes.\n",++m,time2[j],max%60);
else printf("Day #%d: the longest nap starts at %s and will last for %d hours and %d minutes.\n",++m,time2[j],max/60,max%60);
}
return 0;
}
10191
Posted: Fri Nov 11, 2005 10:37 am
by Darko
Description of the problem says "You can assume that no line will be longer than 255 characters", so I assumed that reading 255 characters would do. Actually, I never assumed anything, I just never changed the OJ's Java I/O code, saw '255' thought "well, that should do"... but it didn't.
Is newline character a character?
Darko
Re: [10191] - beware: input line length is 255 + '\n'
Posted: Sat Nov 12, 2005 4:37 pm
by tan_Yui
The newline character is not handled as a character in this problem
because if the newline character was also a character, we couldn't find where is the end of line.
You should read each line until it reaches the newline character,
and not count as the number of elements.
I used the function 'gets' for reading lines on C language.
To store the characters, I prepared the size of array 256.
The last elements of array is for NULL character.
Best regards.
10191(longest nap) wa for >infinity times
Posted: Fri Jan 13, 2006 8:20 am
by Shuvra(CSE-BUET)
I have checked many inputs.Now I find no way other than posting my code. Please tell me about the error .
(After Solaris' reply I got the case I ignored) So I made a change .Now I have ac.
Thanks to Solaris.
.................................................................................................
Code removed after ac
..........................................................................................................
Posted: Fri Jan 13, 2006 11:10 pm
by Solaris
Check the followin input,
1
16:00 18:00 Lectures
...Well
Posted: Mon Aug 28, 2006 1:43 pm
by justjoy
Output...
If minute of the longest nap start time is 0
You must print 00
No 0
p.s
I'm Korean Middle School Student..
I can't English very well.
sorry,
10191
Posted: Sun Jan 07, 2007 10:15 pm
by zaman
I've tested the inputs in the forum. But still getting wrong answer.Please suggest any sample input that doesn't pass it .Here is my code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void INSERT_SORT(int *l,int lim){
int j,i,key;
for(j=1;j<lim;j++){
key=l[j];
i=j-1;
while(i>-1&&l>key){
l[i+1]=l;
i=i-1;
l[i+1]=key;
}
}
}
void main(){
int s, i, temp, nap_duration, nap_start[102], nap_finish[102], nap_start1, nap_finish1,day = 1; char ch[300],*token;
bool flag = false;
//freopen("G:\\input.txt","r",stdin);
while( scanf("%d", &s) != EOF){
if(flag == true )
printf("\n");
flag =true;
//strcpy(starting_time, "10:00");
nap_start[0] = 600;
nap_duration = 0;
gets(ch);
for( i = 1; i <= s ; i++ ){
gets(ch);
token = strtok( ch," ");
nap_finish = ((( token[0] - '0' ) *10 + ( token[1] - '0' )) *60 ) + (( token[3] - '0' ) *10 + ( token[4] - '0' ));
token = strtok( NULL," ");
nap_start = ((( token[0] - '0' ) *10 + ( token[1] - '0' )) *60 ) + (( token[3] - '0' ) *10 + ( token[4] - '0' ));
}
INSERT_SORT(nap_finish,i);
INSERT_SORT(nap_start,i);
nap_finish = 1080 ;
for( int i = 1; i <= s ; i++ ){
temp = nap_finish - nap_start[i-1];
if( nap_duration < temp ){
nap_duration = temp;
nap_start1 = nap_start[i-1];
nap_finish1 = nap_finish;
}
}
temp = (nap_finish - nap_start[i-1]);
if( nap_duration < temp ){
nap_duration = temp;
nap_start1 = nap_start[i-1];
nap_finish1 = nap_finish;
}
printf("Day #%d: the longest nap starts at %d:",day,(nap_start1/60));
if((nap_start1%60) < 10)
printf("0%d and will last for ",(nap_start1%60));
else
printf("%d and will last for ",(nap_start1%60));
if( nap_duration < 60)
printf("%d minutes.",nap_duration);
else
printf("%d hours and %d minutes.",(nap_duration/60),(nap_duration%60));
day++;
}
}
thanks in advance.
Keep in posting...
What's the Longest nap?
Posted: Mon Apr 02, 2007 10:35 pm
by mhayter1
Can someone please help me. This problem is supposed to be easy, but I'm having a very tough time with it. My output seem right. Can someone point out the error in my code or give my inputs to break it. Thank you!
Code: Select all
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
using namespace std;
struct events
{
int s,e;
};
bool gre(const events &a,const events &b)
{
if(a.s<b.s)return 1;
return 0;
}
void myitoa(unsigned long long Val,string &STr1,int BAse)
{
STr1="";
static const char AsCII[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char tptr[70];
int InDeX=0;
for(unsigned long long i=Val;i!=0;i/=BAse)
{
tptr[InDeX]=AsCII[(i%BAse)];
InDeX++;
}
bool WoRKed=0;
for(int j=0;j<InDeX;j++)
{
STr1=tptr[j]+STr1;
WoRKed=1;
}
if(!WoRKed)
STr1="0";
}
int main()
{
int num_events;
string input;
for(int day=1;cin>>num_events;day++)
{
cin.get();
if(num_events==0)
{
cout<<"Day #"<<day<<": the longest nap starts at 10:00 and will last for 8 hours and 0 minutes.\n";
continue;
}
int longesnap=0;
vector<events>orderofact;
for(int i=0;i<num_events;i++)
{
getline(cin,input);
int hour,minutes;
char buffer;
istringstream iss(input);
iss>>hour>>buffer>>minutes;
int start=hour*60+minutes;
iss>>hour>>buffer>>minutes;
int end=hour*60+minutes;
events t;
t.s=start;
t.e=end;
orderofact.push_back(t);
}
sort(orderofact.begin(),orderofact.end(),gre);
int realstart=600;
int realend=1080;
int maxdiff=0;
int ls=600;
if(maxdiff<orderofact[0].s-realstart)
{
maxdiff=orderofact[0].s-realstart;
ls=realstart;
//cout<<"first worked\n";
}
if(maxdiff<realend-orderofact[num_events-1].e)
{
maxdiff=realend-orderofact[num_events-1].e;
ls=orderofact[num_events-1].e;
//cout<<"second worked\n";
}
for(int i=1;i<num_events;i++)
{
if(maxdiff<orderofact[i].s-orderofact[i-1].e)
{
maxdiff=orderofact[i].s-orderofact[i-1].e;
ls=orderofact[i-1].e;
//cout<<"maxdiff= "<<maxdiff<<" ls= "<<ls<<endl;
}
}
int shours=ls/60;
int smin=ls%60;
string starttime;
myitoa(shours,starttime,10);
string temp;
myitoa(smin,temp,10);
if(smin==0)
temp+="0";
starttime=starttime+":"+temp;
if(maxdiff<60)
{
cout<<"Day #"<<day<<": the longest nap starts at "<<starttime<<" and will last for "<<maxdiff<<" minutes.\n";
}
else
{
int mhours=maxdiff/60;
int mmins=maxdiff%60;
string hours;
myitoa(mhours,hours,10);
string mins;
myitoa(mmins,mins,10);
cout<<"Day #"<<day<<": the longest nap starts at "<<starttime<<" and will last for "<<hours<<" hours and "<<mins <<" minutes.\n";
}
}
return 0;
}
Thanks for you're help.