• 简易聊天机器人O(∩_∩)O哈哈哈~


    使用说明:随便输入点什么,复制到Dev-c++上即可使用。(正在完善请多谅解︿( ̄︶ ̄)︿)

    #include<iostream>
    #include<cstdio>
    
    using namespace std;
    char c[1001];
    int main()
    {
    	cout<<"My name is Jackson,your good friend!"<<endl;
    	cout<<"If you have something disturbing,please tell me!QwQ"<<endl;
    	if(gets(c))
    	{
    		cout<<"hi,what can I do for you?"<<endl;
    	}
    	if(gets(c))
    	{
    		cout<<"Do not worry,I will try my best to help you!"<<endl;
    	}
    	return 0;
    }
    

      

      (*^__^*) 嘻嘻……

    还有两个在网上找的,也挺好玩的^_^

    #include<iostream>
    #include<string>
    #include<ctime>
    #include<cstdlib>
    
    int main()
    {
        std::string Response[]={
    		"I heard you!",
    		"SO, you are talking to me.",
    		"CONTINUE,I am listening.",
    		"Very interesting conversation.",
    		"TELL me more..."
    	};
    	srand((unsigned) time(NULL));
    	std::string sInput="";
    	std::string sResponse="";
    	while(1){
    		std::getline(std::cin,sInput);
    		int nSelection=rand()%5;
    		sResponse=Response[nSelection];
    		std::cout<<sResponse<<std::endl;
    	}
    	return 0;
    }
    

     

    #pragma warning(disable:4786)
    
    #include<iostream>
    #include<string>
    #include<vector>
    #include<ctime>
    #include<cstdlib>
    
    using namespace std; 
    
    const int MAX_RESP=3;
    
    typedef vector<string>vstring;
    
    vstring find_match(string input);
    void copy(char*array[],vstring &v);
    
    
    typedef struct
    {
        char*input;
        char*responses[MAX_RESP];
    }record;
    
    record KnowledgeBase[]=
    {
    	{"What is your name", 
    	{"My name is chatterbot2.",
    	 "You can call me chatterbot2.",
    	 "Why do you want to know my name?"}
    	},
    
    	{"Hi", 
    	{"Hi there!",
    	 "How are you?",
    	 "Hi!"
    	}
    	},
    
    	{"How are you",
    	{"I'm doing fine!",
    	 "I'm doing well and you?",
    	 "Why do you want to know how am I doing?"}
    	},
    
    	{"Who are you",
    	{"I'm an a.I program.",
    	 "I think that you know who I'm.",
    	 "Why are you asking?"}
    	},
    
    	{"Are you intelligent",
    	{"Yes,of course.",
    	 "What do you think?",
    	 "Actualy,I'm very intelligent!"}
    	},
    
    	{"Are You real",
    	{"Does that question really maters to you?",
    	 "What do you mean by that?",
    	 "I'm as real as I can be."}
    	}
    };
    
    size_t nKnowledgeBaseSize = sizeof(KnowledgeBase)/sizeof(KnowledgeBase[0]);
    
    
    int main()
    {
        srand((unsigned) time(NULL));
    
        std::string sInput="";
        std::string sResponse="";
    
        while(1)
    	{
            cout<<">";
            getline(cin,sInput);
            vstring responses=find_match(sInput);
            if(sInput=="Bye")
    		{
                cout<<"It was nice talking to you user,see you next time!"<<endl;  
                break;
            } 
            else if(responses.size()==0)
    		{
                cout<<"I'will try me best to help you!"<<endl;
            }
            else{
                int nSelection=rand()%MAX_RESP;
                sResponse=responses[nSelection];
    			cout<<sResponse<<std::endl; 
            } 
        } 
    
        return 0;
    }
    
    // make a  search for the  user's input 
    // inside the database of the program 
    vstring find_match(string input)
    { 
        vstring result;
        for(int i=0;i<nKnowledgeBaseSize;++i)
    	{  
            if(string(KnowledgeBase[i].input)==input)
    		{ 
                copy(KnowledgeBase[i].responses,result); 
                return result;
            } 
        } 
        return result; 
    }
    
    void copy(char  *array[],vstring &v)
    { 
        for(int i=0;i<MAX_RESP;++i)
    	{
            v.push_back(array[i]);
        }
    }
    

      原blog上都是大写输出,我稍微改了一下(⊙v⊙)

     ↖(^ω^)↗~~O(∩_∩)O哈哈~~

    附上一个blog链接好啦~(≧▽≦)/~啦啦啦

    C++_写一个聊天机器人

    “为什么圆规能画出圆?” “因为心不变,脚在动。”
  • 相关阅读:
    给列表项标记添加自定义图像
    双飞翼布局与圣杯布局
    CSS3 calc()
    CSS滚动视差
    应用层层面面试题汇总
    Linux下OpenSSL 安装
    深入理解:Android 编译系统
    ios 好去处
    IBOutlet & IBAction
    ar技术序章-SDK介绍和选择
  • 原文地址:https://www.cnblogs.com/xrj1229/p/9230798.html
Copyright © 2020-2023  润新知