那一個英文字的字母加起來是等於100? (a字頭) 註: 英文字母, a代表的數值是1、 b代表的數值是2、 如此類推... z代表的數值是26。 這個英文字就是來自「態度」的英文。 attitude a = 1 t = 20 t = 20 i = 9 t = 20 u = 21 d = 4 e = 5 加總後等於 100 了。 For example: excellent, culture, standards // // ViewController.swift // Word100 // // Created by louis on 8/7/2015. // Copyright (c) 2015年 louis. All rights reserved. // import UIKit class ViewController: UIViewController { @IBOutlet weak var shw1: UILabel! @IBOutlet weak var shw2: UILabel! @IBOutlet weak var shw3: UILabel! @IBOutlet weak var input_text: UITextField! @IBAction func checkSum(sender: AnyObject) { shw1.text = "輸入的字串:"+input_text.text // 計算出字串的長度 var len = count(input_text.text) shw2.text = "字串的長度:\(len)個字母" // 設定 sum 變量 var sum:UInt32 = 0 // 把 input_text 換成大階並存放在 s 中 let s = String(input_text.text).uppercaseString.unicodeScalars for index in indices(s){ let value = s[index].value if (65<=value && value <= 90) { sum += value-64 } } shw3.text = "字串的總和:"+String(sum) } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. shw1.text = "輸入的字串" shw2.text = "字串的長度" shw3.text = "字串的總和" } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }