Click here to view the problem
/***
Md. Namzul Hasan
Shahjalal University of Science & Technology,Sylhet.
hasan08sust@gmail.com
***/
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define load(array,size) for(int i=0 ; i<size ; i++) cin>>array[i] ;
#define new_line pf("\n")
#define clear_data(array) memset(array,0,sizeof(array))
#define highest_int 2147483647
char arr1[] = "AEIOUYWH";
char arr2[] = "BPFV";
char arr3[] = "CSKGJQXZ";
int soundexcode(char ch)
{
if(strchr(arr1,ch))
return 0 ;
if(strchr(arr2,ch))
return 1 ;
if(strchr(arr3,ch))
return 2 ;
if(ch=='D' || ch=='T')
return 3 ;
if(ch=='L')
return 4 ;
if(ch=='M' || ch=='N')
return 5 ;
if(ch=='R')
return 6 ;
}
int main()
{
char name[30] ;
char data[30] ;
pf (" NAME SOUNDEX CODE\n");
int code ,i, temp,len,indx ;
while(gets(name))
{
data[0] = name[0] ;
len = strlen(name) ;
data[1] = data[2] = data[3] = '0' ;
code = soundexcode(name[0]) ;
indx =1 ;
for(i=1 ; i<len ; i++)
{
temp =soundexcode(name[i]) ;
if(temp!=code && temp!=0)
data[indx++] = temp+ '0' ;
if(temp!=code)
code = temp ;
}
pf("%9s%s", "",name) ;
for(i=0 ; i<25-len ; i++)
pf(" ") ;
pf("%c%c%c%c\n",data[0],data[1],data[2],data[3]) ;
}
pf (" END OF OUTPUT\n");
return 0;
}
/***
Md. Namzul Hasan
Shahjalal University of Science & Technology,Sylhet.
hasan08sust@gmail.com
***/
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define load(array,size) for(int i=0 ; i<size ; i++) cin>>array[i] ;
#define new_line pf("\n")
#define clear_data(array) memset(array,0,sizeof(array))
#define highest_int 2147483647
char arr1[] = "AEIOUYWH";
char arr2[] = "BPFV";
char arr3[] = "CSKGJQXZ";
int soundexcode(char ch)
{
if(strchr(arr1,ch))
return 0 ;
if(strchr(arr2,ch))
return 1 ;
if(strchr(arr3,ch))
return 2 ;
if(ch=='D' || ch=='T')
return 3 ;
if(ch=='L')
return 4 ;
if(ch=='M' || ch=='N')
return 5 ;
if(ch=='R')
return 6 ;
}
int main()
{
char name[30] ;
char data[30] ;
pf (" NAME SOUNDEX CODE\n");
int code ,i, temp,len,indx ;
while(gets(name))
{
data[0] = name[0] ;
len = strlen(name) ;
data[1] = data[2] = data[3] = '0' ;
code = soundexcode(name[0]) ;
indx =1 ;
for(i=1 ; i<len ; i++)
{
temp =soundexcode(name[i]) ;
if(temp!=code && temp!=0)
data[indx++] = temp+ '0' ;
if(temp!=code)
code = temp ;
}
pf("%9s%s", "",name) ;
for(i=0 ; i<25-len ; i++)
pf(" ") ;
pf("%c%c%c%c\n",data[0],data[1],data[2],data[3]) ;
}
pf (" END OF OUTPUT\n");
return 0;
}
No comments:
Post a Comment