C# 测试单词的完美度

  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq; using System.Text;
  4 namespace wordperfecTest
  5 {    
  6 class Program
  7     {        
  8 static void Main(string[] args)        
  9 {            
 10 Console.WriteLine("game specification:");     
 11 Console.WriteLine("First: The same letter equal a values!!!");            
 12 Console.WriteLine("start game:");            
 13 for (; ; )            
 14 {                
 15 string str = Console.ReadLine();     
 16  Program P = new Program();                
 17 Console.WriteLine(P.letterValues(str));            
 18 }        
 19 }        
 20 private int letterValues(string str)//字母参数        
 21 {            
 22             int sum = 0;//求和  
 23            int results = 0;//flag
 24             char[] ch = str.ToCharArray();
 25             for (int i = 0; i < ch.Length; i++)
 26             {
 27                 switch (ch[i])   
 28               {    
 29                  case 'a':   
 30                  case'A':  
 31                 results = 1;  
 32                   break;
 33                   case 'b':   
 34                   case 'B':     
 35                     results = 2;
 36                         break;   
 37                   case 'c':  
 38                     case'C':    
 39                      results = 3;
 40                         break;  
 41                    case 'd':   
 42                   case 'D':    
 43                      results = 4;
 44                         break;     
 45                 case 'e':    
 46                  case'E':    
 47                      results = 5;
 48                         break;   
 49                   case 'f':  
 50                    case'F':     
 51                     results = 6;   
 52                       break;      
 53                case 'g':      
 54                case'G':  
 55                        results = 7;  
 56                        break;
 57                     case 'h':     
 58                 case'H':    
 59                      results = 8;
 60                         break;   
 61                   case 'i':     
 62                 case'I':       
 63                   results = 9;   
 64                       break;      
 65                case 'j':        
 66              case'J':        
 67                  results = 10;    
 68                      break;     
 69                 case 'k':  
 70                    case'K':   
 71                       results = 11;
 72                         break;     
 73                 case 'l':        
 74              case'L':          
 75                results = 12;     
 76                     break;     
 77                 case 'm':    
 78                  case'M':       
 79                   results = 13;    
 80                      break;       
 81               case 'n':          
 82            case'N':              
 83            results = 14;        
 84                  break;              
 85        case 'o':              
 86        case'O':             
 87             results = 15;    
 88                      break;        
 89              case 'p':          
 90            case'P':             
 91             results = 16;      
 92                    break;          
 93            case 'q':             
 94         case'Q':          
 95                results = 17;        
 96                  break;          
 97            case 'r':             
 98         case'R':                   
 99       results = 18;          
100                break;           
101           case 's':           
102           case'S':                
103          results = 19
104 break;              
105        case 't':               
106       case'T':                 
107         results = 20;          
108                break;           
109           case 'u':              
110            results = 21;         
111                 break;             
112         case 'v':            
113          case'V':          
114                results = 22;        
115                  break;              
116        case 'w':            
117          case'W':           
118               results = 23;         
119                 break;             
120         case 'x':               
121       case'X':                 
122         results = 24;          
123                break;            
124          case 'y':                
125      case'Y':                
126          results = 25;         
127                 break;            
128          case 'z':                
129      case'Z':                     
130     results = 26;            
131              break;             
132         default:                
133          break;                
134 }            
135      sum += results;    
136          }        
137      return sum;   
138       }   
139   }
140 }

 

posted on 2013-11-30 22:42  小马哥~程序之美  阅读(183)  评论(0编辑  收藏  举报

导航