10420 - List of Conquests

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

Moderator: Board moderators

User avatar
shaon_cse_cu08
New poster
Posts: 50
Joined: Tue May 25, 2010 9:10 am
Contact:

Re: 10420 - List of Conquests WA...plzz Help..

Post by shaon_cse_cu08 » Tue Jul 27, 2010 2:34 pm

Code: Select all

Removed After AC
I figure it out all by myself....

Here is some criticle input for which my code didn't work....

5
Bangladesh
india
India
bangladesh
Bangladesh

Output:
Bangladesh 2
India 1
bangladesh 1
india 1

The program Should Output result even if there is no "LOVELY" women..... :lol: :lol:
I'll keep holding on...Until the walls come tumbling down...And freedom is all around ..... :x

rambo1980
New poster
Posts: 15
Joined: Sun Mar 18, 2012 2:45 pm

10420 WA

Post by rambo1980 » Sun Mar 18, 2012 2:52 pm

Please help me out with this code. I've tried several testcases by myself and my code seems to work perfectly, yet i got WA. Here is the code-

Code: Select all

AC
Last edited by rambo1980 on Fri Apr 06, 2012 3:07 pm, edited 1 time in total.

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

Re: 10420 WA

Post by brianfry713 » Mon Mar 19, 2012 11:02 pm

Change this line:
if(strcmp(countries,countries[j])==1)
to:
if(strcmp(countries,countries[j])>0)
Check input and AC output for thousands of problems on uDebug!

rambo1980
New poster
Posts: 15
Joined: Sun Mar 18, 2012 2:45 pm

Re: 10420 WA

Post by rambo1980 » Tue Mar 20, 2012 10:23 am

wow, it worked! but i'm confused here, i though strcmp(char* ,char* ) was supposed to return any one of -1,0,1 and no other value! i've tested this in codeblocks for several strings! why is the function acting differently now? :\

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

Re: 10420 WA

Post by brianfry713 » Tue Mar 20, 2012 9:26 pm

Check input and AC output for thousands of problems on uDebug!

rambo1980
New poster
Posts: 15
Joined: Sun Mar 18, 2012 2:45 pm

Re: 10420 WA

Post by rambo1980 » Tue Mar 27, 2012 11:29 am

thanks

gr81
New poster
Posts: 46
Joined: Wed Sep 26, 2012 7:52 pm

Re: 10420 - List of Conquests

Post by gr81 » Sun Jan 13, 2013 9:48 am

there is no involvement of Lovely women in solving this problem..just count the countries which has been visited.

ashrayj11
New poster
Posts: 1
Joined: Tue Jan 22, 2013 2:52 pm

Re: 10420 - List of Conquests

Post by ashrayj11 » Tue Jan 22, 2013 2:57 pm

Please help me out with this problem...i have tried all the suggestion mentioned in this thread already...still getting a WA :(

Code: Select all

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

void ins_alpha(char *, char [2000][75], int [2000], int&);
void sort(char [2000][75], int [2000], int);

int main(void)
{
	int n, number = 0;
	char countries[2000][75] = {{}};
	int frequency[2000] = {};
	cin>>n;
	getchar();
	for(int x=0; x<n; x++)
	{
		char ch[75] = "";
		char country[75] = "";
		cin.getline(ch, 76);
		char* found = strchr(ch, ' ');
		if(found)
			strncpy(country, ch, found-ch);
		else
			strcpy(country, ch);
		ins_alpha(country, countries, frequency, number);
	}
	sort(countries, frequency, number);
	
	for(int i=0; i<number; i++)
	{
		cout<<countries[i]<<" "<<frequency[i];
		if(i!=number-1)
			cout<<"\n";
	}
	return 0;
}

void ins_alpha(char* country, char countries[2000][75], int frequency[2000], int& number)
{
	for(int n=0; n<2000; n++)
		if(strcmp(countries[n], country)==0)
		{
			frequency[n]++;
			return;
		}
	strcpy(countries[number], country);
	frequency[number]++;
	number++;
}

void sort(char countries[2000][75], int frequency[2000], int number)
{
	for(int i=0; i<number-1; i++)
	{
		int min = i;
		for(int j=i+1; j<number; j++)
			if(strcmp(countries[j], countries[min]) < 0)
				min = j;
		int temp_f = frequency[i];
		frequency[i] = frequency[min];
		frequency[min] = temp_f;
		char temp[75];
		strcpy(temp, countries[i]);
		strcpy(countries[i], countries[min]);
		strcpy(countries[min], temp);
	}
}
Any help/hints will be greatly appreciated !

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

Re: 10420 - List of Conquests

Post by brianfry713 » Tue Jan 22, 2013 11:09 pm

Print a newline at the end of the last line.
Check input and AC output for thousands of problems on uDebug!

awinashse
New poster
Posts: 2
Joined: Tue Jan 29, 2013 10:27 am

Re: 10420 - List of Conquests

Post by awinashse » Tue Jan 29, 2013 10:33 am

I am continuously getting WA for this easy problem.. I have checked my code and edited it 5 times.. I have read all previous post but still dont know which condition I am loosing..
here is my code :-

Code: Select all

#include<stdio.h>
char line[2000][76];
char word[2000][76];
char diff_women[2000][75];
int count_line,count_word;
int input_int(){
 char a;
 int n=0;
 read(sizeof(char),&a,1);
 while(a>=48 && a<=57) {
   n = (n<<3) + (n<<1) + a-48;
   read(sizeof(char),&a,1);
 }
 return n;  
}

input_char() {
  char a;
  int i=0;
  read(sizeof(char),&a,1);
  while((a>=65 && a<=91) || ( a>=97 &&  a<= 123) ||a==' ') {
    line[count_line][i++]= a;
    read(sizeof(char),&a,1);
  } 
}

int compare(const void *x,const void *y) {
 return(strcmp((char*)x,(char*)y));
}

readword() {
   int i=0;
   while((line[count_word][i] != ' ') && (line[count_word][i]!='\0')) {
     word[count_word][i]=line[count_word][i];
     i++;
   }
}

int main() {
 int n,i,count;
 char output_word[76];
 n=input_int();
 while(n--) {
   input_char(); 
   count_line++;
 }
 for(i=0;i<count_line;i++) {
   readword();
   count_word++;
 }
 qsort((char*)word,count_word,sizeof(word[0]),compare);
 strcpy(output_word,word[0]);
 count=1;
 for(i=1;i<=count_word;i++){
  if(strcmp(output_word,word[i])==0)
      count++;
  else {
    printf("%s %d\n",output_word,count);
    count=1;
    strcpy(output_word,word[i]);
  }
 }
 return 0;
}
Please help me with the code.

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

Re: 10420 - List of Conquests

Post by brianfry713 » Tue Jan 29, 2013 11:14 pm

Try reading the input using a standard function such as scanf.
Check input and AC output for thousands of problems on uDebug!

bill8124
New poster
Posts: 8
Joined: Fri Jan 21, 2011 8:13 am

Re: 10420 - List of Conquests

Post by bill8124 » Sat Mar 09, 2013 9:14 pm

I used linked list to solve this problem but made some stupid mistakes before getting AC.
So I provided some I/O below which let me find the problem with my code.
Hope it helps.

Input:

Code: Select all

10
Ta
Tc
Tb
Ac
Ab
Aa
Te
Ar
Am
TT
Output:

Code: Select all

Aa 1
Ab 1
Ac 1
Am 1
Ar 1
TT 1
Ta 1
Tb 1
Tc 1
Te 1

shuvokr
Learning poster
Posts: 66
Joined: Tue Oct 02, 2012 8:16 pm
Location: Bangladesh

Re: 10420 - List of Conquests

Post by shuvokr » Wed Jul 17, 2013 3:49 am

Code: Select all

Accepted...

Code: Select all

enjoying life ..... 

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

Re: 10420 - List of Conquests

Post by uDebug » Tue Feb 25, 2014 8:00 am

bill8124 wrote:So I provided some I/O below which let me find the problem with my code.
Hope it helps.
This is not valid input. The problem clearly states
Each following line, with at most 75 characters, contains a country (the first word) and the name of a woman (the rest of the words in the line) Giovanni loved.
The names of the women are missing from this input.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

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

Re: 10420 - List of Conquests

Post by uDebug » Tue Feb 25, 2014 8:10 am

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

Input:

Code: Select all

6
        Spain        Donna Elvira
    Spain       Donna-Maria Sanchez
   Turkey Alara Dertat
  Turkmenistan Alara Detrat
Turkey Ayla Akl
 Turkey Ceyda Akl
AC Output:

Code: Select all

Spain 2
Turkey 3
Turkmenistan 1
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 104 (10400-10499)”