Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 325    Accepted Submission(s): 139

Problem Description
There is once a king and queen, rulers of an unnamed city, who have three daughters of conspicuous beauty.

The youngest and most beautiful is Psyche, whose admirers, neglecting the proper worship of the love goddess Venus, instead pray and make offerings to her. Her father, the king, is desperate to know about her destiny, so he comes to the Delphi Temple to ask for an oracle.

The oracle is an integer n without leading zeroes.

To get the meaning, he needs to rearrange the digits and split the number into <b>two positive integers without leading zeroes</b>, and their sum should be as large as possible.

Help him to work out the maximum sum. It might be impossible to do that. If so, print `Uncertain`.

 
Input
The first line of the input contains an integer T (1≤T≤10), which denotes the number of test cases.

For each test case, the single line contains an integer n (1≤n<1010000000).

 
Output
For each test case, print a positive integer or a string `Uncertain`.
 
Sample Input
3
112
233
1
 
Sample Output
22
35
Uncertain

Hint

In the first example, it is optimal to split $ 112 $ into $ 21 $ and $ 1 $, and their sum is $ 21 + 1 = 22 $.

In the second example, it is optimal to split $ 233 $ into $ 2 $ and $ 33 $, and their sum is $ 2 + 33 = 35 $.

In the third example, it is impossible to split single digit $ 1 $ into two parts.

 
Source
 
#include<iostream>
#include<stdio.h>
#include<string>
#include<string.h>
using namespace std;
char num[];
int ans[];
int main()
{ int t;
scanf("%d",&t);
getchar();
while(t--)
{
int i=;
int ge[];
for(int j=; j<; j++) ge[j]=;
scanf("%s",num);
int len=strlen(num);
if(len<=)
{
printf("Uncertain\n");
}
else
{
for(int i=;i<len;i++){
ge[num[i]-'']++;
}
int cnt=;
for(int i=;i>=;i--){
for(int j=;j<ge[i];j++){
ans[cnt++]=i;
}
}
// for(int i=0;i<cnt;i++) cout<<ans[i]<<" ";
int flag=;
if(ans[cnt-]==){
flag=;
for(int i=cnt-;i>;i--){
if(ans[i]!=){
flag=;
ans[cnt-]=ans[i];
ans[i]=;
break;
}
}
}
if(!flag){
printf("Uncertain\n");
continue;
}
int tmp=;
// for(int j=0; j<len; j++) cout<<ans[j]<<endl;
//cout<<len;
for(int j=len-; j>=; j--)
{
ans[j]=ans[j]+tmp;
if(j==len-) ans[j]=ans[j]+ans[len-];
if(ans[j]>=)
{
ans[j]-=;
tmp=;
}
else
{
tmp=;
}
}
if(tmp)
{
printf("");
}
for(int i=; i<=len-; i++)
printf("%d",ans[i]);
printf("\n");
} }
return ;
}
 这道题没有什么好说到,是一道送分题。
但是注意两个相加到数都必须是正整数,所以如果ans到最后一位是0到话要和非第一位到非0数交换,如果没有非0的数,则
没法完成神谕。

7-16 Bestcoder a Oracle的更多相关文章

  1. Ubuntu 16.04安装Oracle 11gR2入门教程图文详解

    概述 Ubuntu版本:ubuntu-16.04.3-desktop-amd64 Oracle版本:linux.x64_11gR2_database ------------------------- ...

  2. 巡检脚本OS+Oracle

    巡检脚本 主机巡检脚本:OSWatcher.sh Oracle巡检脚本:ORAWatcher.sh 脚本使用方法 1.建立脚本放置目录 # mkdir /var/collect 2.把脚本ORAWat ...

  3. C#连接Oracle数据库(直接引用dll使用)

    转载至:http://www.cnblogs.com/gguozhenqian/p/4262813.html 项目中有个功能需要从一台Oracle数据库获取数据,本以为是很简单的事情,直接将原来的Sq ...

  4. linux环境下安装oracle数据库 原文在卡卡100http://www.cnblogs.com/kaka100

    centos55_oracle11gr2_install   第一个阶段:安装centos55 a:安装centos5.5   用图形界面安装  硬盘 16G 注意:用图形界面安装.. 第二个阶段:配 ...

  5. RHEL每天定时备份Oracle

    步骤: (1)创建脚本文件bak_112.sh,内容如下(自动按当前日期备份数据库): #!/bin/sh export ORACLE_BASE=/u01/app/oracle; ORACLE_HOM ...

  6. oracle进程

    http://blog.csdn.net/leshami/article/details/5529239 Oracle实例和Oracle数据库(Oracle体系结构) 几类进程:用户进程,服务进程,后 ...

  7. Oracle迁移MySQL笔记

    1,--在oracle代表注释 ,mysql/* */,# 2,|| oracle里面是表示连接符号,比如 A||B 那么就是AB 3,databaseLink创建好之后,比如名字为db_link_b ...

  8. Oracle bbed 实用示例-----File Header Reset

    一.查看当前环境 1.1 当前控制文件中的SCN号 [oracle@ora10 ~]$ sqlplus /nolog SQL :: Copyright (c) , , Oracle. All righ ...

  9. Oracle DBA 的常用Unix参考手册(一)

    作为一名Oracle DBA,在所难免要接触Unix,但是Unix本身又是极其复杂的,想要深刻掌握同样很不容易.那么到底我们该怎么入手呢?Donald K Burleson 的<Unix for ...

随机推荐

  1. 白话空间统计之:Moran&#39;s I(莫兰指数)

    前两天聊了空间统计学里面的两个经典概念,今天来说说第一篇文章留下的大坑:Moran's I. 首先,Moran's I这个东西.官方叫做:莫兰指数,是澳大利亚统计学家帕特里克·阿尔弗雷德·皮尔斯·莫兰 ...

  2. 又学到一个词REPL

    A read–eval–print loop (REPL), also known as an interactive toplevel or language shell 指的是 交互式解释器.

  3. yum安装 lnmp (linux+nginx+php7.1+mysql5.7)

    1.第一步先更新yum update 2.yum安装nginx安装nginx最新源:yum localinstall http://nginx.org/packages/centos/7/noarch ...

  4. Win8安装程序出现2502、2503错误解决方法

    我是在安装VMware virtualbox的时候遇到的这个问题,上网百度了一下发现这是个在win8系统上安装程序时才会遇到的. 究其原因这个问题还是由于权限问题导致的,解决方法如下: 1,ctrl+ ...

  5. URLRewrite地址重定向的实现

    URLRewrite就是我们通常说的地址重写,用户得到的全部都是经过处理后的URL地址.其优点有: (1)提高安全性,可以有效的避免一些参数名.ID等完全暴露在用户面前,如果用户随便乱输的话,不符合规 ...

  6. ssh远程连接

    SSH 是Secure Shell protocol 的简写,经由将联机的封包加密的技术,来进行资料的传递,安全. telnet: tcp:23 基于字符 任意客户端登录远程服务器 明文 无需验证 易 ...

  7. tomcat中server.xml配置详解(转载)(二)

    转载自:https://www.cnblogs.com/starhu/p/5599773.html 一:<Connector>元素 由Connector接口定义.<Connector ...

  8. MAC OS X Yosemite的PyQt4配置记录

    MAC OS X Yosemite的PyQt4配置记录 声明: 1)本报告由博客园bitpeach撰写,版权所有,免费转载,请注明出处,并请勿作商业用途. 2)若本文档内有侵权文字或图片等内容,请联系 ...

  9. setImmediate 函数详解

    1.兼容性 只有IE10以上的IE浏览器才支持. 2.用途 https://developer.mozilla.org/zh-CN/docs/Web/API/Window/setImmediate 该 ...

  10. hibernate 关系映射之 双向外键关联一对一

    在上一篇博客内容的基础上做了以下修改,即可实现.   注解方式:   package com.bjsxt.hibernate; import javax.persistence.Entity; imp ...