Page 2 of 2

wrong answer

Posted: Mon Nov 15, 2010 5:26 pm
by BUET
what WA?

Code: Select all

#include<iostream>
#include<cstring>
#include <map>
#include<string>
#include<cmath>
#include<cctype>
#include <cstdlib>


using namespace std;

const int LineMax = 72;

const int NULLCHAR = '\0';

typedef char LineType[LineMax];



class LineClass
   {
   private:
      LineType Info;
   public:
      LineClass(void);
      LineClass(LineType Str);
      void GetLine(LineType Line) const;
   };

class frequen
{
private:
	int cnt;
public:
	frequen(int a)
	{
		cnt = a;
	}
	void inc()
	{
		cnt++;
	}
	int get()
	{
		return cnt;
	}
};



LineClass::LineClass(void)
   {
        Info[0] = NULLCHAR;
   }



LineClass::LineClass(LineType Str)
   {
		strcpy(Info, Str);
   }



void LineClass::GetLine(LineType Line) const
   {
		strcpy(Line, Info);
		
   }



bool operator<(LineClass LHS, LineClass RHS)
   {

	   LineType Left, Right;

	    LHS.GetLine(Left);
	    RHS.GetLine(Right);

	   if (strcmp(Left, Right) < 0)
		  return true;
	   else
		  return false;
   }



void LoadData(map<LineClass,frequen> & Dictionary);
void Lookup(LineType Target, map<LineClass, frequen> & Dictionary);


class BigInteger
{
public:

	BigInteger();

	int setbychar(const char *num);

	int add(BigInteger &a1,BigInteger &a2);

	const char*print();

	~BigInteger();

private:

	int size;
	
	char *content;

};

BigInteger :: BigInteger() : size(0),content(0){}

int BigInteger::setbychar(const char *num)
{
	size = strlen(num);

	content = new char[size+1];

	strcpy(content,num);

	return 0;

}

int BigInteger::add(BigInteger &a1, BigInteger &a2)
{
	char *temp;
	int i,j,k,c,t;

	size = a1.size > a2.size ? a1.size: a2.size;
	size++;

	temp = new char [size+1];

	memset(temp,32,sizeof(temp));

	i = a1.size -1;

	j = a2.size - 1;

	k = size - 1;

	temp[size] = '\0';

	c = 0;

	while( i>= 0 || j >= 0 || c != 0)
	{
		t = c;
		c = 0;
		if( i >= 0)
		{
			t += a1.content[i] - 48;
			i--;
		}
		if( j >= 0 )
		{
			t += a2.content[j] - 48;
			j--;
		}
		c = t/10;
		t = t%10;
		temp[k--] = t + 48;
	}

	if( k >= 0)
	{
		strcpy(temp,temp+k+1);
	}

	size -= (k+1);
	if( content != NULL)
		delete content;
	content = temp;

	return 0;
}


const char *BigInteger::print()
{
	return content;
}

BigInteger::~BigInteger()
{
	if( content != NULL)
	{
		delete content;
	}
}

//if(myMap.find("STL") != myMap.end()) { ... }

int main(void)
{

    int i,n;
    
    char in[10000];
    int value;
    
    char sum[1000000];
    char temp[1000000];
    
    map<LineClass, frequen> Dictionary;
    LineType Target;
	map<LineClass,frequen>::iterator it;
	pair<map<LineClass, frequen>::iterator,bool> ret;
	
	int a,b;
	
    BigInteger a1[5001];
		
	cin >> a >> b;
	
	getchar();
	
	for( i = 0; i  < a ; i++)
	{
         cin >> in >> value;
         getchar();
         ret = Dictionary.insert(pair<LineClass,frequen>(LineClass(in),
              frequen(value)));
    }
    
    getchar();
    
    char *p;
    char val[100000];
	
    while(b--)
    {
           
           sum[0] = '\0';
           while(1)
           {  
                   gets(in);
                   if(strlen(in) == 1 && in[0] == '.')
                   break;
                p = strtok(in," ,.,!?&@#\"");
    		    
    			while( p != NULL)
    			{
    				
    				if( Dictionary.find(LineClass(p)) != Dictionary.end())
                    {
                        int num = Dictionary.find(LineClass(p)) -> second.get();
                        
                        //itoa (num,val,10);
                        sprintf(val, "%d", num);
                        a1[0].setbychar(val);
                        a1[1].setbychar(sum);
                        a1[2].add(a1[0],a1[1]);
                        strcpy(sum,a1[2].print());
                        
                    }
    				p = strtok(NULL," ,.,!?&@#\"");
    			}
        }
        
        cout << sum << endl;
              
    }




	return 0;
}

Re: 10295 - Hay Points

Posted: Tue Nov 16, 2010 6:17 am
by sohel
You can use this site - http://uvatoolkit.com/problemssolve.php - to compare your output with the right one by generating cases of your own.

Re: 10295 - Hay Points

Posted: Thu Dec 19, 2013 3:53 am
by Angry Bird
Getting WA. Please check.

Code: Select all

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int m,n,i,money,j;
    char s[1000],s1[10000];
    char ss,ssp[]=".";
    while(scanf("%d%d",&m,&n)!=EOF)
    {
        vector< pair< string, int > >v;
        vector<int>vm;

        map<string,int>::iterator im;


        for(i=0; i<m; i++)
        {
            scanf("%s %d",&s,&money);
            v.push_back(make_pair(s,money));
        }

        for(j=0; j<n; j++)
        {
            map<string,int>mp;
            while(scanf("%s",&s1))
            {
                if(s1[0]==ssp[0])
                    break;

                char *p;
                p=strtok(s1," ");
                while(p!=NULL)
                {
                    mp[p]++;
                    p=strtok(NULL," ");
                }
            }

            int sum=0;
            pair<string,int>p1,p2;

            for(i=0; i<v.size(); i++)
            {
                p1=v[i];
                sum+=(p1.second*mp.find(p1.first)->second);
            }
            printf("%d\n",sum);
        }
    }
    return 0;
}


Re: 10295 - Hay Points

Posted: Wed Jan 08, 2014 3:10 am
by brianfry713
Doesn't match the sample I/O

Re: 10295 - Hay Points

Posted: Fri Jan 17, 2014 6:35 pm
by uDebug
Here's some input / output that I found useful during testing / debugging.

Input:

Code: Select all

9 7
administer 100000
spending 200000
manage 50000
responsibility 25000
expertise 100
skill 50
money 75000
serious 100000
great 100000
the incumbent will administer the spending of kindergarden milk money
and exercise responsibility for making change he or she will share
responsibility for the task of managing the money with the assistant
whose skill and expertise shall ensure the successful spending exercise
.
this individual must have the skill to perform a heart transplant and
expertise in rocket science
.
seriooous
.
serious
   .
gr8t
.
great and serious
        .
great great great great great great great great great great
great great great great great great great great great great
great great great great great great great great great great
great great great great great great great great great great
great great great great great great great great great great
great great great great great great great great great great
great great great great great great great great great great
great great great great great great great great great great
great great great great great great great great great great
great great great great great great great great great great
.
AC Output:

Code: Select all

700150
150
0
100000
0
200000
10000000

Re: 10295 - Hay Points

Posted: Fri Jan 17, 2014 6:52 pm
by uDebug
Angry Bird wrote:Getting WA. Please check.
Your code's unecessarily complicated. How about using a map to store the dictionary words and their corresponding values?

Also, you're considering char[] as std::string - these are different types. Think about ditching the tokenizing all together - read what Solaris has to suggest.

Finally, at the very least, it might be a good idea to at least test your code with the sample input provided in the problem before you put it on here saying you're getting WA.