Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
Idea de solucion adhoc, la parte principal del es convertir int a string,
en c++11 se puede hacer de forma facil usando to_string(int x)
PResentation error: cuidar siempre imprimir un salto de linea entre casos y tambien al final de la salida
**/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <string>
using namespace std;
/**Usar esta implementación si no usas c++11
string to_string(int i)
{
std::stringstream ss;
ss << i;
return ss.str();
}
**/
int t;
int pre,act;
int mini,maxi;
int c;
int main(){
scanf("%d",&t);
c=1;
while(t){
printf("Case %d:\n",c);
scanf("%d",&pre);
mini=pre;
t--;
while(t>-1){
if(t!=0)
scanf("%d",&act);
if( (act-pre)!=1 ){
maxi=pre;
if(maxi==mini){
printf("0%d\n",maxi);
}
else{
int aux=maxi-mini;
string mi=to_string(mini);
string ma=to_string(maxi);
for(int i=ma.length()-1,e=mi.length()-1,count=1;i>=-1&&e>=-1;i--,e--,count*=10){
if( (mi[i]==ma[e] &&aux<count)||i==-1 ){
printf("0%d-",mini);
cout<<ma.substr(e+1);
printf("\n");
break;
}
}
}
mini=act;
}
pre=act;
t--;
}
scanf("%d",&t);
c++;
printf("\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.