#include <iostream> #include <cstdlib> #include <cstring> #include <string> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <map> #define inf 0x3f3f3f3f #pragma comment(linker, "/STACK:16777216") #define eps 1e-6 #define ll long long using namespace std; inline int ReadInt() { char ch = getchar(); if (ch==EOF) return -1; int data = 0; while (ch < '0' || ch > '9') { ch = getchar(); if (ch==EOF) return -1; } do { data = data*10 + ch-'0'; ch = getchar(); } while (ch >= '0' && ch <= '9'); return data; } int s[110]; int main() { int i=0,n; while((s[i]=ReadInt())!=-1) i++; n=i; sort(s,s+n); printf("%d",s[0]); int flag=0; for(i=1;i<n;i++) { if(s[i]==s[i-1]) continue; if(s[i]-s[i-1]==1) { if(flag) continue; else { flag=1; printf("-"); continue; } } if(flag==1) { flag=0; printf("%d",s[i-1]); } printf(",%d",s[i]); } if(flag==1) { flag=0; printf("%d",s[i-1]); } puts(""); return 0; }
时间: 2024-12-31 03:54:11