C/C++の宿題を片付けます 59代目
■ このスレッドは過去ログ倉庫に格納されています
0340デフォルトの名無しさん
2006/01/29(日) 23:05:28#include <iostream>
#include <string>
#include <map>
int main(void)
{
std::map<std::string,std::string>e;
e["Hokkaido"] = "099-30-000";
e["Tohoku"] = "0995-1-111";
e["Kanto"] = "099-32-222";
e["Chubu"] = "099-33-333";
e["Kinki"] = "0995-4-444";
std::map<std::string,std::string>::iterator itr = e.begin(),end = e.end();
for(;itr != end;++itr)
if(itr->second.find("0995")==0)itr->second.replace(3,2,"-5");// 地域番号 "0995-x-xxx" を "099-5x-xxx"
std::cout << std::endl;
std::cout << "検索用文字列を入力して下さい: ";
std::string s;
std::cin >> s;
int k = 0;
for(itr = e.begin();itr != end;++itr)
if(itr->first.find(s)!=itr->first.npos){
std::cout<< itr->first << ": " << itr->second << std::endl;
k++;// k の初期値は0
}
if(k==0) std::cout << "入力された文字列に一致するものは見つかりませんでした " << std::endl;
return 0;
}
■ このスレッドは過去ログ倉庫に格納されています