列表

详情


NC14636. 简单的双拼输入法

描述

双拼输入法是指汉字的声母、韵母各用一个字母(或个别符号)代替构成的拼音编码。采用这种拼音输入法输入汉字时,用户只需要击键两次便可以键入一个汉字的拼音。例如小鹤双拼,输入“中国”的“中”字,可键入vs完成字音输入。

以下是某双拼的编码方案:

上图中红色代表对应的声母,蓝色代表对应的韵母。

简单的说,双拼的基本原理就是,把某个多字母的声韵母(比如zh、ch、sh、uang、ong、eng等)放在一个指定的键上,那么任何拼音组合都只需要两个击键,比如zhuang=vh,chong=is。

对于给定的双拼编码,请转换成全拼编码。

本题保证给出的每个汉字编码由一个声母和一个韵母构成,不存在零声母的情况。



输入描述

输入第一行包括一个整数n(0<n<=100),表示汉字的个数,接下来的第1~n+1行分别是n个句子,每行第一个数m,表示
这句话中汉字的个数,之后的m个双拼编码之间由空格隔开。
每行不超过100个汉字

输出描述

输出共有n行,将每行句子中的双拼编码转换成对应的全拼编码,每个汉字之间用空格隔开。

示例1

输入:

5
2 ys fw
3 ni hc wa
2 ww rr
20 qu nm yr ye ui hx ui dg ru vz yt uh lq uc tz rf yt hl hy hz
20 jb nm yr ye ui hx yu dg yi jq bu jm qu nm rf lw mj iy uj xq

输出:

yong fei
ni hao wa
wei ruan
qu nian yuan ye shi hua shi deng ru zhou yue shang liu shao tou ren yue huang hun hou
jin nian yuan ye shi hua yu deng yi jiu bu jian qu nian ren lei man chun shan xiu

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++(g++ 7.5.0)(g++7.5.0) 解法, 执行用时: 4ms, 内存消耗: 404K, 提交时间: 2023-04-18 19:39:39

#include <bits/stdc++.h>
#include <ext/pb_ds/hash_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

// #pragma GCC optimize(1)
// #pragma GCC optimize(2)
// #pragma GCC optimize(3,"Ofast","inline")

#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f

#define lowbit(x)   ((x) & -(x))
#define all(x)      x.begin(), x.end()
#define set_all(x, y)   memset(x, y, sizeof (x))
#define endl    '\n'
// #define int long long
#define ff  first
#define ss  second
#define pb   push_back

#define typet typename T
#define typeu typename U
#define types typename... Ts
#define tempt template <typet>
#define tempu template <typeu>
#define temps template <types>
#define tandu template <typet, typeu>

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) do {} while (false)
#endif

using namespace std;
using namespace __gnu_pbds;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, bool> PIB;
typedef pair<double, double> PDD;
typedef long double ld;
// typedef __int128_t i128;

struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		x ^= x << 13;
		x ^= x >> 7;
		x ^= x << 17;
		return x;
	}
	size_t operator () (uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); // 时间戳
		return splitmix64(x + FIXED_RANDOM);
	}
};

const int N = 1010,  M = 2 * N, K = 31;
const double pi = acos(-1), eps =1e-7;
const ull P = 13331;
unordered_map<char, string> ha1{{'q', "iu"},{'w', "ei"}, {'e', "e"}, {'r', "uan"}, {'t', "ue"}, {'y', "un"}, {'u', "u"}, {'i', "i"},
{'o', "uo"}, {'p', "ie"}, {'a', "a"}, {'s', "ong"}, {'d', "ai"}, {'f', "en"}, {'g', "eng"}, {'h', "ang"}, {'j', "an"}, {'k', "uai"}, {'l', "uang"},
{'z', "ou"}, {'x', "ua"}, {'c', "ao"}, {'v', "ui"}, {'b', "in"}, {'n', "iao"}, {'m', "ian"}};
unordered_map<char, string> ha2;

void solut(int I)
{
	for (int i = 0; i < 26; i ++)
	{
		char s = 'a' + i;
		ha2[s] = s;
	}
	ha2['v'] = "zh", ha2['u'] = "sh",ha2['i'] = "ch";
	int n;
	cin >> n;
	for (int i = 1; i <= n; i ++)
	{
		int k;
		cin >> k;
		for (int j = 1; j <= k; j ++)
		{
			char s, c;
			cin >> s >> c;
			cout << (ha2[s] + ha1[c]) << " \n"[j == k];
		}
	}
}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int T;
    T = 1;
    // cin >> T;
    for (int _ = 1; _ <= T; _ ++)
        solut(_);
}

C++14(g++5.4) 解法, 执行用时: 13ms, 内存消耗: 588K, 提交时间: 2020-04-20 21:40:37

#include<iostream> 
#include<string> 
using namespace std; 
int main() { 
    string one[]={ "a","b","c","d","e","f","g", "h","ch","j","k","l","m","n", "o","p","q","r","s","t","sh", "zh","w","x","y","z" }; 
    string two[]={"a","in","ao","ai","e", "en","eng","ang","i","an", "uai","uang","ian","iao","uo", "ie","iu","uan","ong","ue", "u","ui","ei","ua","un","ou" }; 
    int lin; 
    cin>>lin; 
    int index,index1; 
    for(index=0;index<lin;++index) { 
        int num; 
        cin>>num; 
        string s[num]; 
        for( index1=0; index1<num; ++index1) { 
            if(index1==num-1) { 
                cin>>s[index1]; 
                cout<<one[s[index1][0]-'a']+two[s[index1][1]-'a']<<endl; 
            } else {
                cin>>s[index1]; 
                cout<<one[s[index1][0]-'a']+two[s[index1][1]-'a']<<" "; 
            }
        }
    } 
    return 0;
}/*
测试用,没想抄

*/

C++11(clang++ 3.9) 解法, 执行用时: 16ms, 内存消耗: 384K, 提交时间: 2017-12-17 18:41:15

#include<iostream> 
#include<string>
using namespace std;
int main()
{
	string one[] = {
		"a","b","c","d","e","f","g",
		"h","ch","j","k","l","m","n",
		"o","p","q","r","s","t","sh",
		"zh","w","x","y","z"
	};
	string two[] = {
		"a","in","ao","ai","e",
		"en","eng","ang","i","an",
		"uai","uang","ian","iao","uo",
		"ie","iu","uan","ong","ue",
		"u","ui","ei","ua","un","ou"
	};
	int lin;
	cin>>lin;
	int index,index1;
	for(index= 0 ; index < lin;++index)
	{
		int num;
		cin>>num;
		string s[num];
		for(index1 = 0 ; index1 < num ;++index1)
		{
			if(index1 == num - 1)
			{
				cin>>s[index1];
			cout<<one[s[index1][0] -'a']+two[s[index1][1]-'a']<<endl;
			}else
			{
			
				cin>>s[index1];
				cout<<one[s[index1][0] -'a']+two[s[index1][1]-'a']<<" ";
			}
		}
		
	
	}
	return 0;
}

上一题