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. 事务内执行sql修复的简易模板

    -- ============================================= -- Script Template -- ============================= ...

  2. vue-cli 配置路由之间跳转传递参数

    1.有2种方式去传参,如下代码: <template> <div> <div>这里是首页</div> <router-link :to=" ...

  3. scrapy报错:ImportError: No module named 'win32api'

    https://github.com/mhammond/pywin32/releases 下载安装对应的版本即可.

  4. cglib Demo

    转载自:http://huihai.iteye.com/blog/858524 http://www.cnblogs.com/shijiaqi1066/p/3429691.html

  5. iOS开发之使用UICollectionView实现美团App的分类功能【偶现大众点评App的一个小bug】

    郝萌主倾心贡献,尊重作者的劳动成果,请勿转载. 假设文章对您有所帮助,欢迎给作者捐赠,支持郝萌主,捐赠数额任意,重在心意^_^ 我要捐赠: 点击捐赠 Cocos2d-X源代码下载:点我传送 游戏官方下 ...

  6. python将字典内容存入mysql

    1.背景      项目须要,用python实现了将字典内容存入本地的mysql数据库. 比方说有个字典dic={"a":"b","c":& ...

  7. 算法笔记_103:蓝桥杯练习 算法提高 金明的预算方案(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 问题描述 金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间金明自己专用的很宽敞的房间.更让他高兴的是,妈妈昨天对他说:“你的房间需要购买哪些 ...

  8. 使用Loadrunner进行文件的上传和下载

    最近使用loadrunner中需要录制文件的上传和下载,上传功能模块利用录制可以直接实现,下载无法实现,在网上找到了一段代码,自己动手试验了下,发现没有用 辛苦找到的,还是记录下吧 (1)LoadRu ...

  9. proxyTable 解决跨域问题

    1.使用 proxyTable(地址映射表)解决跨域问题(即通过设置代理解决跨域问题): 可以通过设置将复杂的url简化,例如我们要请求的地址是api.xxxxxxxx.com/list/1,可以按照 ...

  10. 使用python进行图像处理-调整图片大小

    python有一个图像处理库——PIL,可以处理图像文件.PIL提供了功能丰富的方法,比如格式转换.旋转.裁剪.改变尺寸.像素处理.图片合并等等等等,非常强大. 举个简单的例子,调整图片的大小: im ...