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. [转]Configure logging in SSIS packages

    本文转自:http://learnsqlwithbru.com/2009/11/26/configure-logging-in-ssis-packages/ n this article we wil ...

  2. Delphi 对象模型学习笔记(转)

    摘要     Borland Object Pascal 对象模型(现在已经正是命名为 Delphi 语言)与其他 OOP 语言一样,都提供了一些基础服务: 如对象创建服务.对象释放服务.对象识别服务 ...

  3. jquery元素节点操作

    jquery元素节点操作 创建节点 var $div = $('<div>'); var $div2 = $('<div>这是一个div元素</div>'); 插入 ...

  4. VB6.0 中 碰到 提示rs对象关闭,不允许操作, 吃一堑长一智

    VB6.0 中 碰到 提示rs对象关闭,不允许操作,  吃一堑长一智 如果碰到 这个错误提示 则请检查 你执行的每一个语句中的数据类型,包括 如果有存储过程的话,还要检查 存储过程中每一个变量和数据表 ...

  5. UVa 615 - Is It A Tree?

    题目:给你一些有向边(端点,长度为1).推断给定的图是否是一棵树. 分析:图论.并查集.树是一个全部点都连接的有向无环图(不连接的是森林). 依照树的定义推断是否有环就可以,有环分成两种: 1.链状环 ...

  6. 解决:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile

    在项目构建的时候遇到了这样的问题:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile(d ...

  7. select()/poll() 的内核实现

    mark 引用:http://janfan.cn/chinese/2015/01/05/select-poll-impl-inside-the-kernel.html 文章 select()/poll ...

  8. Lidgren.Network – an introduction to networking in C# games

    Lidgren.Network – an introduction to networking in C# games http://genericgamedev.com/tutorials/lidg ...

  9. python fabric使用 http://fabric-chs.readthedocs.io/zh_CN/chs/tutorial.html

    fab -u username -p password  -H hostname -P -- cmd   或root@'hostname'  -H多个主机是引号用逗号隔开 -P异步

  10. 用C开发PHP扩展 实例(基础版)

    第一步:建立扩展骨架. cd /usr/local/src/php-5.3.6/ext/ ./ext_skel --extname=laiwenhui 第二步:修改编译参数. cd php-5.3.6 ...