hdu 1013 Digital Roots(水题)
来源:互联网 发布:视频编辑软件pr 编辑:程序博客网 时间:2024/06/05 01:54
小记:这题,咋一看,真简单,各位数字相加求和,减1对9取余再加一 就是answer。 最开始用int 直接提交,WA,好,想了一下,数字肯定蛮大,long long,提交,WA,尼玛,这是大数据的节奏啊。 getchar一个一个的读。好。AC!
思路:一位一位的读入。
#include <iostream>#include <cstdio>using namespace std;int p[] = {9,1,2,3,4,5,6,7,8};int main(){ int n,sum; while(1){ //scanf("%1d",&n); bool flag = 0; char c; int sum = 0; c = getchar(); if(c == '0')break; sum += c - '0'; while((c = getchar()) != '\n'){ if(!flag){ if(c == '\n')continue; flag = 1; } sum += c - '0'; } //if(flag)break; cout<<p[sum%9]<<endl; } return 0;}
高效AC码,仅供参考:
#include<stdio.h>int main(){ int a,c; for(;scanf("%1d",&a),a>0;printf("%d\n",--a%9u+1)) while((c=getchar())-48u<10) a+=c-48; return 0;}
0 0
- hdu 1013 Digital Roots(水题)
- HDU 1013 Digital Roots(水题)
- HDU 1013 Digital Roots【水题】
- HDU 1013 Digital Roots
- HDU 1013 Digital Roots
- hdu 1013 Digital Roots
- HDU 1013 Digital Roots
- HDU 1013 Digital Roots
- HDU 1013 Digital Roots
- hdu 1013 Digital Roots
- HDU 1013 Digital Roots
- hdu 1013 Digital Roots
- HDU--1013--Digital Roots
- hdu 1013 Digital Roots
- hdu 1013 Digital Roots
- HDU 1013Digital Roots
- HDU 1013 Digital Roots
- hdu 1013 Digital Roots
- MySQL函数——MySQL系列(六)
- Day9 - htpasswd 创建,更新用户认证文件
- NAT在NDIS中间层驱动中的实现
- 各种常用的JSON接口,值得收藏
- FLV文件格式
- hdu 1013 Digital Roots(水题)
- 创建基于wicket的web项目入门实例(一)
- 《统计学》读书笔记,第3-7章节
- 洞察网互联网的二十本书
- 传纸条(一) DP
- hdu 1076
- 虚继承与空基类优化
- 程序员面试宝典-第九章-9.1-面试例题3
- 制作带背景图的PDF