<style> .reveal .slides { text-align: left; font-size:32px; } </style> ## 530競技程式培力基地(四) ---- - string - map --- string 的用法 ```cpp= string s="abcd"; cout<<s[0]<<' '<<s.size()<<endl;//輸出 a 4 s+='A'; cout<<s[4]<<' '<<s.size();//輸出 A 5 s.clear()//清除字串 ``` string 是字元的陣列 也可以增加它的大小 --- MAP? ![image](https://hackmd.io/_uploads/rk9x3Gaale.png) ---- map類似查表的工具 | key | value | |--------|---------| | a | 10 | | b | 2 | | c | 13 | ---- ```cpp= map< type , type > mp; // key , value map< string , int > hash; hash["abc"]=12; hash["aaa"]=89; hash["xyz"]=78; cout<<hash["abc"]<<endl;//會輸出 12 cout<<hash["xyz"]<<endl;//會輸出 78 for(auto tmp:hash){ cout<<tmp.first<<' '<<tmp.second<<endl; } /* 輸出結果(sort之後) aaa 89 abc 12 xyz 78 */ ``` --- [題目連結](https://vjudge.net/contest/757407)
{"title":"530競技程式培力基地(四)","description":"array、vector、string","contributors":"[{\"id\":\"2f04e9e4-ce0e-4fa7-9f7e-a3c9ae53239b\",\"add\":881,\"del\":34,\"latestUpdatedAt\":1760534768638}]"}
    85 views