10295 - Hay Points

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

Moderator: Board moderators

BUET
New poster
Posts: 22
Joined: Sun Jun 13, 2010 8:38 am

wrong answer

Post 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;
}
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 10295 - Hay Points

Post 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.
Angry Bird
New poster
Posts: 21
Joined: Mon Apr 08, 2013 8:38 am

Re: 10295 - Hay Points

Post 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;
}

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

Re: 10295 - Hay Points

Post by brianfry713 »

Doesn't match the sample I/O
Check input and AC output for thousands of problems on uDebug!
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 10295 - Hay Points

Post 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
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 10295 - Hay Points

Post 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.
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 102 (10200-10299)”