Codechef Code Crunch 2013 RD-CODE
|
RD-CODEProblem code: MRIU12
|
Problem description.
Code Crunch Heads use RD-CODE for sending messages. It consists of only dots and dashes in sequence.
Below are the RD-CODE for the digits 0 to 9:
- 0 -----
- 1 .----
- 2 ..---
- 3 ...--
- 4 ....-
- 5 .....
- 6 -....
- 7 --...
- 8 ---..
- 9 ----.
Using this code, help Code Crunch Members to find out the RD-CODE of their message.
Users will enter 10 digit phone no. Convert these numbers to RD-CODE and also find no of dots used in the coded data.Input
First line T, will have a single integer having number of test cases followed by T lines of input.
Second line will have a 10-digit number N where N is a positive integer < 9999999999.Output
First line will display the RD-Code for each digit together.
Second line will display the total number of dots in the RD-CODE.Example
Input: 2 9716733117 9716335949 . Output: ----.--….-----….--……--…--.----.------… 23 ----.--….-----…….--…--…..----…..-----. 26
View Code 2013-10-25 16:28:081 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include <map> 3 #include <queue> 4 #include <vector> 5 #include <string> 6 #include <cstdio> 7 #include <cstring> 8 #include <iostream> 9 #include <algorithm> 10 using namespace std; 11 #define maxn 10005 12 #define mod 1000000007 13 #define ll long long 14 #define INF 0x7fffffff 15 int n, m; 16 char s[maxn]; 17 int main(){ 18 int cas = 1; 19 int t; 20 scanf("%d", &t); 21 while (t--){ 22 scanf("%s", s); 23 n = 0; 24 char str[151] = "-----.----..---...--....-.....-....--...---..----."; 25 for (int i = 0; i < strlen(s); i++){ 26 if (s[i]<='5')n += s[i] - '0'; 27 if (s[i] > '5')n += 5 - (s[i] - '0') % 5; 28 for (int j = 0; j < 5; j++)printf("%c", str[(s[i] - '0') * 5 + j]); 29 } 30 printf("\n%d\n", n); 31 } 32 /*while (~scanf("%s", s)){ 33 34 }*/ 35 return 0; 36 }

浙公网安备 33010602011771号