Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define d(x) cout << #x << " = " << (x) << endl;
- #define fr freopen("in.txt", "r", stdin);
- #define fw freopen("out.txt", "w", stdout);
- #define mem(x) memset((x), 0, sizeof((x)));
- #define pb push_back
- #define LL long long
- #define fastIO ios_base::sync_with_stdio(false)
- #define sf scanf
- #define pf printf
- #define SQR(x) ((x)*(x))
- #define sc1(x) scanf("%d", &x)
- #define scb(x, y) scanf("%d %d", &x, &y)
- #define sc3(x, y, z) scanf("%d %d %d", &x, &y, &z)
- #define FOR(i, x, y) for(int i=int(x); i<int(y); i++)
- #define ROF(i, x, y) for(int i=int(x-1); i>=int(y); i--)
- #define all(c) (c.begin(), c.end())
- #define unq(v) sort(all(v)), (v).erase(unique(all(v)),v.end())
- #define EPSILON (1.0E-9)
- #define siz 65000
- int find_group(char ch){
- // string g1 = "BPFV";
- // string g2 = "CSKGJQXZ";
- // string g3 = "DT";
- // string g4 = "L";
- // string g5 = "MN";
- // string g6 = "R";
- vector<string> g;
- g.push_back("BPFV");
- g.push_back("CSKGJQXZ");
- g.push_back("DT");
- g.push_back("L");
- g.push_back("MN");
- g.push_back("R");
- for(int i = 0; i < g.size(); i++){
- for(int j = 0; j < g[i].size(); j++){
- if(ch == g[i][j]){
- return i+1;
- }
- }
- }
- return 0;
- }
- char to_str(int num){
- return '0'+num;
- }
- int main(){
- #ifndef ONLINE_JUDGE
- clock_t tStart = clock();
- freopen("in.txt", "r", stdin);
- freopen("out.txt", "w", stdout);
- #endif
- cout << " ";
- cout.width(25);
- cout << left << "NAME" << "SOUNDEX CODE" << '\n';
- string str;
- while(cin >> str){
- string ans = "";
- ans += str[0];
- // if(str[0] == 'A' or str[0] == 'E' or str[0] == '0' or str[0] == 'O' or str[0] == 'U' or str[0] == 'Y' or str[0] == 'W' or str[0] == 'H'){
- // ans += '0';
- // }
- // else{
- // ans += to_str(find_group(str[0]));
- // }
- int n = str.size();
- for(int i = 1; i < n; i++){
- if(str[i] == 'A' or str[i] == 'E' or str[i] == 'I' or str[i] == 'O' or str[i] == 'U' or str[i] == 'Y' or str[i] == 'W' or str[i] == 'H'){
- continue;
- }
- else{
- int g1 = find_group(str[i-1]);
- int g2 = find_group(str[i]);
- if(g1 == g2){
- continue;
- }
- else{
- ans += to_str(find_group(str[i]));
- }
- }
- }
- string ans2 = "";
- if(ans.size() >= 4){
- for(int i = 0; i < 4; i++) ans2 += ans[i];
- }
- else{
- int i = 0;
- for(i; i < ans.size(); i++) ans2 += ans[i];
- for(i; i < 4; i++) ans2 += '0';
- }
- cout << " ";
- cout.width(25);
- cout << left << str << ans2 << '\n';
- }
- cout.width(32);
- cout << right << "END OF OUTPUT" << '\n';
- #ifndef ONLINE_JUDGE
- printf("\n>>Time taken: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement