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.
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.
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++.
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 !!
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 ]
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.
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);
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.
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.
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
..........................................................................................................
Last edited by Shuvra(CSE-BUET) on Sat Jan 14, 2006 1:31 pm, edited 1 time in total.
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>
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!
#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;
}