2017年6月11日 星期日

(8.9.10)瘋狂程設->CPE顆星廣場

8.What's Cryptanalysis?
內容 :
密碼翻譯(cryptanalysis)是指把某個人寫的密文(cryptographic writing)加以分解。這個程序通常會對密文訊息做統計分析。你的任務就是寫一個程式來對密文作簡單的分析。
輸入說明 : 
輸入的第1列有一個正整數n,代表以下有多少列需要作分析的密文。 接下來的n列,每列含有0或多個字元(可能包含空白字元)
輸出說明 : 
每列包含一個大寫字元(A~Z)和一個正整數。這個正整數代表該字元在輸入中出現的次數。輸入中大小寫(例如:Aa)視為相同的字元。輸出時請按照字元出現的次數由大到小排列,如果有2個以上的字元出現次數相同的話,則按照字元的大小(例如:AH之前)由小到大排列。 請注意:如果某一字元未出現在輸入中,那他也不應出現在輸出中。
範例輸入 : 
3
This is a test.
Count me 1 2 3 4 5.
Wow!!!! Is this question easy?
範例輸出:
S 7
T 6
I 5
E 4
O 3
A 2
H 2
N 2
U 2
W 2
C 1
M 1
Q 1
Y 1

static void Main(string[] args)
        {
            string Input = "";
            int n = 0;
            char[] EngSeveral = new char[26];
            int N = Convert.ToInt32(Console.ReadLine());
            List<char> ToChar = new List<char>();
            int t = 0;
            while (n < N)
            {
                Input = Input + (Console.ReadLine().ToUpper());
                n++;
            }
            foreach (char item in Input.ToCharArray())           
                if (item >= 65 && item <=90 )               
                    EngSeveral[item - 65]++;
            for (int i = 30; i > 0; i--)           
                for (int j = 0; j < 26; j++)               
                    if (EngSeveral[j] == i)                    
                        Console.WriteLine("{0}  {1}", Convert.ToChar(j + 65), i);
        }
9.Decode the Mad man
Once in BUET, an old professor had gone completely mad. He started talking with some peculiar words. Nobody could realize his speech and lectures. Finally the BUET authority fall in great trouble. There was no way left to keep that man working in university. Suddenly a student (definitely he was a registered author at UVA ACM Chapter and hold a good rank on 24 hour-Online Judge) created a program that was able to decode that professor’s speech. After his invention, everyone got comfort again and that old teacher started his everyday works as before.
So, if you ever visit BUET and see a teacher talking with a microphone, which is connected to a IBM computer equipped with a voice recognition software and students are taking their lecture from the computer screen, don’t get thundered! Because now your job is to write the same program which can decode that mad teacher’s speech!

Input
The input file will contain only one test case i.e. the encoded message.
The test case consists of one or more words.

Output
For the given test case, print a line containing the decoded words. However, it is not so hard task to replace each letter or punctuation symbol by the two immediately to its left alphabet on your standard keyboard.

Sample Input
k[r dyt I[o
Sample Output
how are you


static void Main(string[] args)
        {
            string[] Library = { "`1234567890-=\\", "qwertyuiop[]", "asdfghjkl;'", "zxcvbnm,./" };
            char[] remember = new char[20];
            string Input = Console.ReadLine();
            foreach (var chr in Input.ToCharArray())
            {
                if (chr == ' ')
                    Console.Write(' ');
                else
                {
                    for (int h = 0; h < 3; h++)
                    {
                        remember = Library[h].ToCharArray();
                        for (int i = 0; i < remember.Length; i++)
                            if (remember[i] == chr)
                                Console.Write(remember[i - 2]);
                    }
                }
            }
        }



10.Summing Digits
對於所有正整數 n,我們定義一函數 f(n) n 的每一個十進位數字的總合,若再把f(n)代入函數中可得最到 n, f(n), f(f(n)), f(f(f(n)))...最後得到僅有一位數字的值,並定義該值為 g(n)
例如,當 n = 1234567892. :
f(n) = 1+2+3+4+5+6+7+8+9+2 = 47
f(f(n)) = 4+7 = 11
f(f(f(n))) = 1+1 = 2
所以g(1234567892) = 2.
輸入的每一行會有一個正整數 n,其值最大到2,000,000,000,你必須輸出g(n)。輸入是以0值做為結束,該值不需要輸出。

Sample input
2
11
47
1234567892
0
Output for sample input
2
2
2
2


 方法一 
static void Main(string[] args)
        {
            string Input = null;
            List<long> Collect = new List<long>();
            while (Input != "0")
            {
                Input = Console.ReadLine();
                Collect.Add(Convert.ToInt64(Input));
            }
            Console.WriteLine();
            foreach (long item in Collect)
            {               
                long anwser = item;
                while (anwser > 9)
                {
                    long a = 0;
                    foreach (long point in anwser.ToString().ToCharArray())       
                        a = a + (point - 48);
                    anwser = a;
                }
                Console.WriteLine(anwser);
            }

        }

 方法二 
static void Main(string[] args)
        {
            string Input = null;
            List<long> Ouput = new List<long>();
            while (Input != "0")
            {
                Input = Console.ReadLine();
                long Answer = -999;
                char[] Addition;
                while ((Answer > 10 || Answer == -999) && Input != "0")
                {
                    if (Answer == -999)
                    {
                        Addition = new char[100];
                        Addition = Input.ToCharArray();
                    }
                    else Addition = Answer.ToString().ToCharArray();
                    Answer = 0;
                    foreach (var item in Addition)
                    {
                        Answer = Answer + Convert.ToInt64(item - 48);
                    }
                }
                if (Input != "0") Ouput.Add(Answer);
            }
            Console.WriteLine("\nOutput for sample input");
            foreach (var item in Ouput)
            {
                Console.WriteLine(item);
            }
        }

沒有留言:

張貼留言

WinFormTb02

https://drive.google.com/drive/u/0/folders/1UwS9FZ3ELCOK6SAwirHrkxq3z_RSbxJt https://www.youtube.com/watch?v=k7IkIeww_U0&list=PLumjEWemD...