| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:贴个我自己的例子In Reply To:贴个我自己的例子 Posted by:mlion at 2009-09-18 20:00:56 #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
using namespace std;
int main()
{
int n;string nub;int a;long u=0;int b;
cin>>n;
long *p =new long[n];int *pp=new int[n];int q=n;
for(int z=0;z <n;z++){p[z]=-1;pp[z]=1;}
while(n)
{
cin>>nub;
for(int z=0;z <nub.length();z++)
{
if(nub[z]!='-')
{ a=nub[z]-'A'; //对电话号码 映射成long 整刑
if(a <0){b=nub[z]-'0';u=u*10+b;} // a <0表示号码输入时候是数字符
if(a>=0&&a <16){u=u*10+(a/3+2);} // A到P字母映射 (P-A)/3+2=15/3+2=7 P映射到7
if(a>=16){u=u*10+((a-1)/3+2);} //R到Y字母映射成数字 因为中间少了Q故每个都a-1.
} //u就是7个号码组成的 7位数 长整型。
}
n=n-1;
for(int z=q-1;z>=n-1;z--) //p[]初始化全位-1.并把u从后往前放如数组p[].
{
if(u==p[z]){pp[z]=pp[z]+1;break;} // 新生成的u 和p[]数组从后往前比较。若有等于 pp[]记录相等个数。并且相等的u在p[] 只放置一个
if(u!=p[z]&&!(p[z]+1)){p[z]=u;break;}// 从后往前,若u在p[]中没有相等的,且发现有p[z]=-1(表示没有号码放入)则把u放入数组。
}
u=0; //u归0 ,为下个号码。
}
vector <long> ht;
while((p[q-1]+1)&&q)
{
if(pp[q-1]>=2){u=p[q-1]*10+pp[q-1];ht.push_back(u);} // 对重复数pp[]>=2的提取出来,整个号码*10,把重复数放入放入号码的个位数中
q=q-1;
}
if(ht.empty()){cout < <"No duplicates." < <endl;return 0;} // 如果vector 是空的则表示没有 重复号码 输出
std::sort(ht.begin(),ht.end()); //号码长整型 按从小到大排列(这就是字典序)
stringstream ss;long t;
vector <long>::iterator iter;string str1;string str2;string test="0";
for(iter=ht.begin();iter!=ht.end();++iter)
{
t=(*iter/100000);ss < <t;ss>>str1;ss.clear(); // 号码前三位提取出来成str1
t=(*iter%100000)/10;ss < <t;ss>>str2;ss.clear(); //号码后三位提取 str2
while(3-str1.length()) //若前三位 长度小于三 在str1前补0
{
str1=test+str1;
}
while(4-str2.length()) //若后四位长度小于4 在str2 前补0
{
str2=test+str2;
}
cout < <str1 < <"-" < <str2 < <" " < <*iter%10 < <endl; // 输出
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator