Documente Academic
Documente Profesional
Documente Cultură
Concordance
i
Rate This
Input: The first line of the data set for this problem is an integer that
represents the number of lines that follow.
Sample Input:
https://tausiq.wordpress.com/2009/10/03/concordance/ 1/5
10/23/2017 Concordance | Solved Programming Problems
Sample Input:
3
DOO WOP DOO WOP DOO WOP
SHOOBY DOOBY DOO
WOO WOO
Sample Output:
DOO 1 1 1 2
DOOBY 2
SHOOBY 2
WOO 3 3
WOP 1 1 1
Solutions :
1 #include <stdio.h>
2 #include <string.h>
3
4 int main ()
5 {
6 int lines;
7 scanf ("%d", &lines);
8 getchar ();
9
10 char input [6] [42];
11 char words [42] [42];
12 char temp [42];
13 int count_word = 0;
14
15 for ( int i = 0; i < lines; i++ ) {
16 gets (input [i]);
17 strcpy (temp, input [i]);
18
19 char *token = strtok (temp, " ");
20
21 while ( token ) {
22 strcpy (words [count_word++], token);
23 token = strtok (NULL, " ");
24 }
25 }
26
27 for ( int i = 0; i < count_word; i++ ) {
28 for ( int j = i + 1; j < count_word; j++ ) {
29 if ( strcmp (words [i], words [j]) > 0 ) {
30 strcpy (temp, words [i]);
31 strcpy (words [i], words [j]);
32 strcpy (words [j], temp);
33 }
34 }
35 }
36
37 for ( int i = 0; i < count_word; i++ ) {
38 if ( strcmp (temp, words [i]) != 0 ) {
39 printf ("%s\t", words [i]);
40
41 for ( int j
https://tausiq.wordpress.com/2009/10/03/concordance/ = 0; j < lines; j++ ) { 2/5
10/23/2017 Concordance | Solved Programming Problems
Advertisements
Easy Problems
1. Moktar Ali
MAY 18, 2014 AT 11:59 PM
#include
#include
#include
#include
int main()
https://tausiq.wordpress.com/2009/10/03/concordance/ 3/5
10/23/2017 Concordance | Solved Programming Problems
int main()
{
int n,i=0,k=0,map_size;
cin>>n>>ws;
map_size=n;
while(n–)
{
string str;
getline(cin,str);
m[i]=str;
while(pch !=NULL)
{
ma[k]=pch;
//char * cs = pch;
str2=ma[k];
str2.insert(str2.length(),” “);
ma[k]=str2;
k++;
pch=strtok(NULL,” “);
//cout<<"\n strtok="<<k<<endl;
}
i++;
}
cout<<ma[0];
for(i=0;i<k;i++)
{
size_t found=-1;
for(int j=0;j<map_size;j++)
{
str2=m[j];
https://tausiq.wordpress.com/2009/10/03/concordance/ 4/5
10/23/2017 Concordance | Solved Programming Problems
str2=m[j];
str2.insert(str2.length()," ");
found=str2.find(ma[i],found+1);
if (found!=string::npos)
{
if( ma[i].length() !=0){
//cout<<"i="<<i<<" ma="<<ma[i]<<" found at "<<j+1<<" line at "
<<found<< " ma length="<<ma[i].length()<<endl;
cout<<" "<<j+1;
if(ma[i]!=ma[i+1])
{
found=string::npos;
cout<<endl<<ma[i+1];
}
i++;
j–;
}
}
}
i–;
//cout<<"\ni="<<i<<" ma@i="<<ma[i]<<"e"<<endl;
}
return 0;
}
i
Rate This
https://tausiq.wordpress.com/2009/10/03/concordance/ 5/5