Maplewing

8/29 C++: STL map

Aug 29th, 2015
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <map>
  5. using namespace std;
  6.  
  7. int main(){
  8.     map<string,string> m;
  9.     m["Apple"] = "0930999666";
  10.     m["Ben"] = "0945875421";
  11.     m["Candy"] = "0932542151";
  12.    
  13.     string name;
  14.     cin >> name;
  15.     cout << m[name] << endl;
  16.    
  17.     /*
  18.     C:
  19.     char name[100][20], phone[100][20];
  20.     strcpy( name[0], "Apple" );
  21.     strcpy( phone[0], "0930999666" );
  22.    
  23.     char input[20];
  24.     scanf("%s", input);
  25.    
  26.     for( int i = 0 ; i < 1 ; i++ ){
  27.         if( strcmp(input, name[i]) == 0 ){
  28.             printf("%s\n", phone[i]);
  29.             break;
  30.         }
  31.     }
  32.     */
  33.    
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment