Page 4 of 5

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

Posted: Tue Jul 27, 2010 2:34 pm
by shaon_cse_cu08

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:

10420 WA

Posted: Sun Mar 18, 2012 2:52 pm
by rambo1980
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

Re: 10420 WA

Posted: Mon Mar 19, 2012 11:02 pm
by brianfry713
Change this line:
if(strcmp(countries,countries[j])==1)
to:
if(strcmp(countries,countries[j])>0)

Re: 10420 WA

Posted: Tue Mar 20, 2012 10:23 am
by rambo1980
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? :\

Re: 10420 WA

Posted: Tue Mar 20, 2012 9:26 pm
by brianfry713

Re: 10420 WA

Posted: Tue Mar 27, 2012 11:29 am
by rambo1980
thanks

Re: 10420 - List of Conquests

Posted: Sun Jan 13, 2013 9:48 am
by gr81
there is no involvement of Lovely women in solving this problem..just count the countries which has been visited.

Re: 10420 - List of Conquests

Posted: Tue Jan 22, 2013 2:57 pm
by ashrayj11
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 !

Re: 10420 - List of Conquests

Posted: Tue Jan 22, 2013 11:09 pm
by brianfry713
Print a newline at the end of the last line.

Re: 10420 - List of Conquests

Posted: Tue Jan 29, 2013 10:33 am
by awinashse
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.

Re: 10420 - List of Conquests

Posted: Tue Jan 29, 2013 11:14 pm
by brianfry713
Try reading the input using a standard function such as scanf.

Re: 10420 - List of Conquests

Posted: Sat Mar 09, 2013 9:14 pm
by bill8124
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

Re: 10420 - List of Conquests

Posted: Wed Jul 17, 2013 3:49 am
by shuvokr

Code: Select all

Accepted...

Re: 10420 - List of Conquests

Posted: Tue Feb 25, 2014 8:00 am
by uDebug
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.

Re: 10420 - List of Conquests

Posted: Tue Feb 25, 2014 8:10 am
by uDebug
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