返回信息流#include<stdio.h>
#include<string.h>
void main(){
int power(int, int);
int chtoint(char c);
void insertSort(int a[], int N);
char telstr[20];
int telnum, n;
char *m;
int i, N;
scanf("%d", &N);
int res[N];
for(i=0; i<N; i++){
telnum = 0;
scanf("%s", telstr);
for(m=telstr, n=6; *m; m++){
if((*m)!='-'){
telnum += chtoint(*m) * power(10, n);
n--;
}
}
res[i] = telnum;
}
insertSort(res, N);
int z;
void repeatCount(int a[], int N);
repeatCount(res, N);
}
void repeatCount(int a[], int N){
//count repetitions and output.
int i=0, j, tmp, cnt;
int flag = 0;
while(i<N){
cnt = 1;
tmp = a[i];
while(a[++i]==tmp){
cnt++;
}
if(cnt!=1){
printf("%03d-%04d %d\n", a[i-1]/10000, a[i-1]%10000, cnt);
flag = 1;
}
}
if(flag==0)
printf("No duplicates.\n");
}
int chtoint(char c){
//map char to int
switch(c){
case '0': return 0;
case '1': return 1;
case '2': case 'A': case 'B': case 'C': return 2;
case '3': case 'D': case 'E': case 'F': return 3;
case '4': case 'G': case 'H': case 'I': return 4;
case '5': case 'j': case 'K': case 'L': return 5;
case '6': case 'M': case 'N': case 'O': return 6;
case '7': case 'P': case 'R': case 'S': return 7;
case '8': case 'T': case 'U': case 'V': return 8;
case '9': case 'W': case 'X': case 'Y': return 9;
}
}
int power(int b, int i){
//the power function
int pow = 1;
while(i--){
pow *= b;
}
return pow;
}
void insertSort(int a[], int N){
//insertion sort
int i, j, tmp, k;
for(i = 1; i < N; i++){
tmp = a[i];
for(j = i; j > 0 && a[j-1] > tmp; j--){
a[j] = a[j-1];
}
a[j] = tmp;
}
}
这是一条镜像帖。来源:北邮人论坛 / cpp / #80755同步于 2014/7/10
CPP机器人发帖
poj 1002,水题一个,却总是wrong answer,不知遗漏了哪些细节
SheetaDola
2014/7/10镜像同步0 回复
订阅后,新回复会通过你的通知中心匿名送达。
0 条回复
暂无回复 · 你可以订阅本帖等待新回复。