首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

关于字符串数组中 不反复的字符串的个数

2012-09-16 
关于字符串数组中 不重复的字符串的个数马上大家帮帮忙 帮我想想 用c怎么写出在一个字符串数组中 不重复字

关于字符串数组中 不重复的字符串的个数
马上大家帮帮忙 帮我想想 用c怎么写出在一个字符串数组中 不重复字符串的个数

[解决办法]

探讨
for(int i=count-1;i>=0;i--)
{
int flag=0;
for(int j=count-1;j>=0;j--)
{
if(i!=j)
{
if(strcmp(p[i],p[j])==0)
{
flag=1;
break;
}
}
continue;
}
if(flag==0)
n++;
}
printf("不重复的单词一共%d个",n……

[解决办法]
C/C++ code
#include <set>#include <string>#include <vector>using namespace std;const char * test1 = "123456";const char * test2 = "124578";const char * test3 = "123456";std::set<int> a;int main(){    vector<string>temp;    temp.push_back( test1 );    temp.push_back( test2 );    temp.push_back( test3 );    set <string> lTemp;    for ( int i = 0 ; i < temp.size() ; ++i )    {        lTemp.insert( temp.at( i ) );    }    int result = lTemp.size();    char say [64] = {0};    sprintf( say , "%s%d" , "The Not Same String Number Is:" , result );    printf( say );    system( "pause" );} 

热点排行