PAT1023. Have Fun with Numbers
//水题,但是考点不水,可能用的strlen属于string库,但是只能用于字符,不能用数字,因为\0就是0.出现0无法判断,其次二倍时有可能有进位
//第一次在二倍进位上出了问题
#include<stdio.h>
#include<string.h>
int main()
{
//freopen("input.txt","r",stdin);
char s[];
int s1[];
int has[];
memset(has,,sizeof(has));
scanf("%s",s);
int i,len=strlen(s);
for(i=;i<len;i++) //hash
{
has[s[i]-'']++;
}
int c=,len1=;
for(i=len-;i>=;i--) //计算2倍
{
int m=c+(s[i]-'')*;
has[m%]--; //hash 比较
s1[len1++]=m%;
c=m/;
}
if(c!=)s1[len1++]=c;
if(len1!=len)printf("No\n"); //进位
else{
for(i=;i<;i++)
if(has[i]!=)break; //出现次数不一样
if(i<)printf("No\n");
else printf("Yes\n");
}
for(i=len1-;i>=;i--) //不论yes or no 输出
printf("%d",s1[i]);
printf("\n");
}
PAT1023. Have Fun with Numbers的更多相关文章
- PAT1023. Have Fun with Numbers (20)
#include <iostream> #include <map> #include <algorithm> using namespace std; strin ...
- Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range
在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- [LeetCode] Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
- [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [LeetCode] Bitwise AND of Numbers Range 数字范围位相与
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- [LeetCode] Valid Phone Numbers 验证电话号码
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...
- [LeetCode] Consecutive Numbers 连续的数字
Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...
随机推荐
- Debug program crash with dump file.
1. Task manager, -> find the process for the program which crashed. 2. Right click the process -& ...
- (WPF) 文件和文件夹选择对话框。
点击button,选择一个excel文件,并将文件名显示在textbox上. private void btnSelectErrorTableFile_Click(object sender, Rou ...
- Java语法基础动手动脑实践
输出结果为: 0.05+0.01=0.0600000000000000051.0-0.42=0.58000000000000014.015*100401.49999999999994123.3/100 ...
- dynamic基元类型
C#编译器允许将一个表达式的类型标记为dynamic.还可以将一个表达式的结果放到一个变量中,并将变量的类型标记为dynamic. 代码使用dynamic表达式/变量来调用一个成员是,编译器会生成特殊 ...
- android之Widget01
ExampleAppWidgetProvider.java package com.example.mars_2600_widget01; import android.appwidget.AppWi ...
- Python基础08 面向对象的基本概念
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 谢谢逆水寒龙,topmad和Liqing纠错 Python使用类(class)和对 ...
- 第11章 System V 信号量
11.1 概述 信号量按功能分:二值信号量.计数信号量.信号量集:其中二值信号量和计数信号量指的是Posix信号量,信号量集指的是System V信号量.
- 无侵入方面编程-用HttpModule+SoapExtension监视页面执行参数(二)
上一篇文章 "无侵入方面编程-用HttpModule+SoapExtension监视页面执行参数(一)"中,我们实现了监视每个页面的执行情况和调用WebService的简单信息. ...
- 20145305 《Java程序设计》第2周学习总结
教材学习内容总结 1.boolean类型可表示true与false 2.储存值超类型范围会出现溢值 3.变量在命名时不可以使用数字作为开头,不可以使用一些特殊字符,不可以与JAVA关键词同名,不可以与 ...
- mysql 错误1054
问题,当查询数据时,输入字符串是数字时,可以查询,但当输入字母字符串时却不能查询,总是提示错误1054 解决:将字符串打上单引号 字段对应的值如果为字符或字符串类型的时候,应用英文单引号括起来,你用的 ...