10879 - Code Refactoring

All about problems in Volume 108. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

rajib2k10
New poster
Posts: 4
Joined: Fri Feb 10, 2012 12:02 am

UVa 10879. getting WA. Please help

Post by rajib2k10 » Fri May 16, 2014 10:51 pm

I didn't find the bug. Thanks in advance.

Code: Select all

#include <algorithm>
#include <bitset>
#include <cstring>
#include <cctype>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <stack>
#include <stdio.h>
#include <sstream>
#include <utility>
#include <vector>
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define pi acos(-1.0)
#define N 1000000
#define LL long long

using namespace std;

int main()
{
    freopen("data.txt","r",stdin);
    freopen("output.txt","w",stdout);

    int test;
    long long int number;
    cin>>test;
    for(int i=1;i<=test;i++)
    {
        cin>>number;
        int j = 2;
        while(1)
        {
            long long int result = number/j;
            long long int temp1=result,temp2=j;
            if(result*j==number&&j!=number)
            {
                cout<<"Case #"<<i<<": "<<number<<" = "<<result<<" * "<<j;
x:              j = j + 1;
                result = number/j;
                if(result*j==number&&result!=temp1&&result!=temp2&&j!=temp1&&j!=number)
                {
                    cout<<" = "<<result<<" * "<<j;
                    break;
                }
                else
                    goto x;
            }
            else
            {
                j++;
                continue;
            }

        }cout<<"\n";
    }

return 0;
}


brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: UVa 10879. getting WA. Please help

Post by brianfry713 » Tue May 20, 2014 10:26 pm

Don't read and write to files
Check input and AC output for thousands of problems on uDebug!

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 10879 - Code Refactoring

Post by uDebug » Tue Jun 10, 2014 11:38 am

Here's some input I found useful during testing / debugging.

Input:

Code: Select all

4
10000000
18
525
9862342
AC Output:

Code: Select all

Case #1: 10000000 = 2 * 5000000 = 4 * 2500000
Case #2: 18 = 2 * 9 = 3 * 6
Case #3: 525 = 3 * 175 = 5 * 105
Case #4: 9862342 = 2 * 4931171 = 7 * 1408906
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

Post Reply

Return to “Volume 108 (10800-10899)”