棒!!

来源:互联网 发布:搜狗seo关键词优化 编辑:程序博客网 时间:2024/04/27 19:31

代码:

#include <iostream>#include <iomanip>using namespace std;int pstrcmp(char *str1, char *str2);int main(void){    char *s[81]= {"Tudou","Shanyaodan","Yangyu","Malingshu"};    int i=0,j=0;    cout<<"土豆大PK:"<<endl;    cout<<setw(12)<<" ";    for(; i<4; i++)    {        cout<<setw(12)<<s[i];    }    cout<<endl;    for(i=0; i<4; i++)    {        cout<<setw(12)<<s[i];        for(j=0; j<4; j++)        {            cout<<setw(12)<<pstrcmp(s[i],s[j]);        }        cout<<endl;    }    return 0;}//str>str2,返回1//str==str2,返回0//str<str2,返回-1int pstrcmp(char *str1, char *str2){    char *p=str1,*q=str2;    while(*p==*q&&*p!='\0'&&*q!='\0')    {        p++;        q++;    }    if (*p>*q)        return 1;    else if(*p<*q)        return -1;    else        return 0;}

运行结果:

学习心得:

   看了贺老写的这个程序,,不禁心生慨叹呐。。

0 0
原创粉丝点击