1、输入一行,输出一行,直到文件末尾,除去重复的数。
/*
STL解决
*/
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
void GetNoReplicates()
{
string str;
vector<int> result;
vector<int>::iterator iter;
while(cin>>str)
{
int i=0;
int temp;
while(str[i]!='\0')
{
temp=0;
while(str[i]!='\0'&&str[i]!=',')
{
temp=10*temp+str[i]-'0';
i++;
}
if(str[i]=='\0')
{
result.push_back(temp);
vector<int> copy;
copy.push_back(result[0]);
for(int j=1; j<result.size();j++)
{
iter=find(copy.begin(),copy.end(),result[j]);
if(iter==copy.end())
{
copy.push_back(result[j]);
}
}
for(int k=0;k<copy.size();k++)
{
if(k==copy.size()-1)
{
cout<<copy[k]<<endl;
}
else
{
cout<<copy[k]<<",";
}
}
result.clear();
break;
}
else
{
result.push_back(temp);
i++;
}
}
}
}
void main()
{
GetNoReplicates();
}
/*
set记录排除集
*/
#include<iostream>
#include<string>
#include<set>
using namespace std;
void GetNoReplicates()
{
int temp[4096];
int result[4096];
string str;
int num;
int j=0;
memset(temp,0,sizeof(int)*4096);
set<int> hash;
while(cin>>str)
{
int i=0;
int r=0;
while(str[i]!='\0')
{
num=0;
while(str[i]!='\0'&&str[i]!=',')
{
num=10*num+str[i]-'0';
i++;
}
if(str[i]=='\0')
{
temp[j++]=num;
result[r++]=temp[0];
hash.insert(temp[0]);
for(int k=1;k<j;k++)
{
if(0==hash.count(temp[k]))
{
result[r++]=temp[k];
hash.insert(temp[k]);
}
}
for(k=0;k<r;k++)
{
if(k==r-1)
cout<<result[k]<<endl;
else
cout<<result[k]<<",";
}
j=0;
hash.clear();
break;
}
else
{
temp[j++]=num;
i++;
}
}
}
}
void main()
{
GetNoReplicates();
}
2、天数问题
输入:MM-YYYY,MM为月份,YYYY为年份,例如:08-2014
输出:指定年份和月份的天数。例如,08-2014,对应输出为31。
#include<iostream>
#include<string>
using namespac