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. synchronized 线程同步

    synchronized  通常用来形容一次方法的调用,调用一旦开始,调用者必须等到方法调用返回后,才能继续执行后续的操作. 1.demo package demo1; public class My ...

  2. 隐藏系统EFI分区Z盘

    找到C:\Windows\System32\cmd.exe程序, 右键单击cmd 选择以管理员身份运行, 打开命令提示符,输入以下命令(不区分大小写)DiskPart回车List空格volume回车s ...

  3. 搭建dubbo-admin-2.5.3

    dubbo管理界面 一,安装zookeeper 1,下载包zookeeper-3.3.3.tar.gz 2,解压 tar zxvf zookeeper-3.3.3.tar.gz cd zookeepe ...

  4. centos下安装pyspider

    环境: * CentOS release 6.4 (Final) * Python 2.6.6 pip install pyspider   ,发现lxml没有安装好 直接sudo yum insta ...

  5. js中字符串转换为数字

    js 字符串转化成数字的三种方法主要有 转换函数.强制类型转换.利用js变量弱类型转换. 1. 转换函数: js提供了parseInt()和parseFloat()两个转换函数.前者把值转换成整数,后 ...

  6. Android图片下载以及缓存框架

    实际开发中进行图片下载以及缓存的框架 介绍一下开发中常见图片加载框架的使用和对比一下优缺点. 1.Picasso 框架 在Android中开发,常需要从远程获取图片并显示在客户端,当然我们可以使用原生 ...

  7. 通过LR监控Linux服务器性能

    1)设置监控服务器要监控 UNIX 资源,必须配置 rstatd 守护程序.注意,可能已经配置了 rstatd守护程序,因为当计算机收到一个 rstatd 请求时,该计算机上的 inetd 自动激活r ...

  8. js 终止 forEach 循环

    1.因为 forEach() 无法通过正常流程终止,所以可以通过抛出异常的方式实现终止. try{ var array = ["first","second", ...

  9. 优秀运维人员20道必会iptables面试题(转载)

    (一)企业面试口试题 1.详述iptales工作流程以及规则过滤顺序? 2.iptables有几个表以及每个表有几个链? 3.iptables的几个表以及每个表对应链的作用,对应企业应用场景? 4.画 ...

  10. 解决树莓派新内核无法使用18B20和没有声音的问题

    现在新版的树莓派内核由于为了兼容树莓派2和树莓派B+等以前的版本,采用了和原来不同的内核运行方式,使用了设备树的方式,更加灵活.但是由于可能不习惯这样的方式以及没太多相关这方面的介绍,导致很多用户更新 ...