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;
}