Friday, April 7, 2017

URI Online Judge Solution 1652 | Deli Deli

URI Online Judge | 1652

Deli Deli

Local Contest, University of Ulm DE Germany
Timelimit: 1
Mrs. Deli is running the delicatessen store "Deli Deli". Last year Mrs. Deli has decided to expand her business and build up an online store. She has hired a programmer who has implemented the online store.
Recently some of her new online customers complained about the electronic bills. The programmer had forgotten to use the plural form in case that an item is purchased multiple times. Unfortunaly the programmer of Mrs. Deli is on holiday and now it is your task to implement this feature for Mrs. Deli. Here is a description how to make the plural form:
  1. If the word is in the list of irregular words replace it with the given plural.
  2. Else if the word ends in a consonant followed by "y", replace "y" with "ies".
  3. Else if the word ends in "o", "s", "ch", "sh" or "x", append "es" to the word.
  4. Else append "s" to the word.

Input

The first line of the input file consists of two integers L and N (0 ≤ L ≤ 20, 1 ≤ N ≤ 100). The following L lines contain the description of the irregular words and their plural form. Each line consists of two words separated by a space character, where the first word is the singular, the second word the plural form of some irregular word. After the list of irregular words, the following N lines contain one word each, which you have to make plural. You may assume that each word consists of at most 20 lowercase letters from the english alphabet ('a' to 'z').

Output

Print N lines of output, where the ith line is the plural form of the ith input word.
Sample InputSample Output
3 7
rice rice
spaghetti spaghetti
octopus octopi
rice
lobster
spaghetti
strawberry
octopus
peach
turkey
rice
lobsters
spaghetti
strawberries
octopi
peaches
turkeys



URI Online Judge Solution 1652 | Deli Deli in C++

#include <iostream>
#include <cstring>
#include <string>
#include <map>
  
using namespace std;
#define sc1(a) scanf("%s", &a)
#define sc2(a,b) scanf("%d %d", &a, &b)
#define for(i,a,n) for(int (i) = (a); (i) < (n); (i)++)
bool isv(char ch){return ch == 'a' || ch == 'e' || ch =='i' || ch =='o' || ch == 'u';}
bool is3(char ch){return ch == 'o' || ch == 's' || ch =='ch' || ch =='sh' || ch == 'x';}
bool is4(char ch1, char ch2){return (ch1 == 'c' && ch2 == 'h') || (ch1 == 's' && ch2 == 'h');}
int main(void)
{
    char c, ca;
    int l, n, sz;
    string key, value, tmp;
    map<string,string> map;
    while(sc2(l,n) == 2)
    {
        map.clear();
        cin.ignore();
        for(i,0,l)
        {
            cin >> key >> value;
            map.insert(pair<string,string>(key,value));
        }
        cin.ignore();
        for(i,0,n)
        {
            cin >> key;
            sz = key.length();
            c = key[sz-1], ca = key[sz-2];
             
            if(!(map.find(key) == map.end())) cout << map[key] << '\n';
            else if(!(isv(ca)) && c == 'y'){
                tmp = key.substr(0,sz-1);
                cout << tmp << "ies" << '\n';
            }else if(is3(c) || is4(ca,c)) cout << key << "es" << '\n';
            else cout << key << "s" << '\n';
        }
    }
    return 0;
}



Note:
If you face any problem still comment here..


No comments:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.