C/C++の宿題片付けます 143代目at TECH
C/C++の宿題片付けます 143代目 - 暇つぶし2ch307:デフォルトの名無しさん
10/11/23 09:44:29
>>302
#include <iostream>
#include <string>
#include <cstdlib>
#include <fstream>
unsigned str2number(std::string str){
unsigned ret=7743; // 必要ならここに日付を数値化したものを足す time(NULL)/(60*60*24) みたいに
for(unsigned i=0;i<str.length();i++) ret=ret*37+str[i];
return ret;
}
int main(void){
std::string name, buf;
std::ifstream ifs("data.txt");

std::cout << "名前を入力してください : ";
getline(std::cin, name);
srand(str2number(name));
std::cout << name << " さんの" << std::endl;
while(getline(ifs, buf)){
if(buf[0]=='#'){
std::string theme, result;
theme=buf.substr(1);
for(int i=1;getline(ifs, buf);i++){
if(buf=="") break;
if(rand()%i==0) result=buf;
}
std::cout << theme << " は " << result << " です"<< std::endl;
}
}
return 0;
}


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch