Search found 4 matches

by Davidacm
Fri May 10, 2002 9:29 am
Forum: Volume 1 (100-199)
Topic: 100 - The 3n + 1 problem
Replies: 1394
Views: 318271

Help!! No. 100

I write the program in C++. It worked well on my computer but got a W.A.
Can anyone tell me what the problem is?
[cpp]
#include<iostream>
using namespace std;

void main()
{
int i, j;
int maxlength;
while (cin>>i>>j)
{
maxlength=0;
for(int y=i; y<=j; y++)
{
int count=1;
int z=y;
while(z ...
by Davidacm
Tue May 07, 2002 3:03 am
Forum: Volume 1 (100-199)
Topic: 100 - The 3n + 1 problem
Replies: 1394
Views: 318271

But how do i check whether i have reached the end of the file and do i have to use cin.ignore at the end of each line as indicated in the smaple input file?
by Davidacm
Fri May 03, 2002 10:47 am
Forum: Volume 1 (100-199)
Topic: 100 - The 3n + 1 problem
Replies: 1394
Views: 318271

what about this? cost 10.04s

[cpp]
#include <fstream>
using namespace std;

void main()
{
int i, j;
int maxlength;
ifstream fin("stdin.txt");

while (!fin.eof())
{
fin>>i>>j;
fin.ignore(1,'\n');

maxlength=0;
for(int y=i; y<=j; y++)
{
int count=1;
int z=y;
while(z!=1)
{
if (z%2==0)
z=z/2;
else
z=z*3+1 ...
by Davidacm
Fri May 03, 2002 6:49 am
Forum: Volume 1 (100-199)
Topic: 100 - The 3n + 1 problem
Replies: 1394
Views: 318271

problem 100, time limit exceeded, dreaded 10.030s

#include <fstream>
using namespace std;

void main()
{
int i[50], j[50];
int line=0;
int maxlength[50];
ifstream fin("stdin.txt");
while (!fin.eof())
{
line++;
fin>>i[line]>>j[line];
fin.ignore(1,'\n');
maxlength[line]=0;
for(int y=i[line]; y<=j[line]; y++)
{
int count=1;
int z=y ...

Go to advanced search