Codeforces Round #450 (Div. 2)+刘汝佳紫书3-8 (C语言整数模拟除法)
来源:互联网 发布:网络课程哪个好 编辑:程序博客网 时间:2024/06/04 18:06
基本模板:
#include <iostream>#include <cstdio>using namespace std;int main(){ int a,b; int tem; while(~scanf("%d%d",&a,&b)){ for(int i=0;i<15;i++){ tem=a/b; a-=b*tem; a*=10; printf("%d",tem); if(!i) printf("."); } printf("\n"); }}
题目链接:http://codeforces.com/contest/900/problem/B
#include <iostream>#include <cstdio>#include <cstdlib>#include <queue>#include <cstring>#include <algorithm>#include <cmath>#define LL long longusing namespace std;int main(){ int a,b,c; int tem,cnt,flag; while(~scanf("%d%d%d",&a,&b,&c)){ cnt=flag=0; a*=10; for(int i=0;i<1000005;i++){ if(a==0){ if(c==0){ flag=1; cnt++; } break; } tem=a/b; a-=b*tem; cnt++; a*=10; //printf("%d",tem); if(tem==c){ flag=1; break; } } if(flag) printf("%d\n",cnt); else printf("-1\n"); }}
题目链接:vj上 UVa 202 自行开 即可
代码如下:
//即使是循环小数,但可能并不是从第一位小数开始循环,这样在加括号和循环节的长度上都会出错,WA了数次#include <iostream>#include<cstdio>#include<cstring>using namespace std;int rm[1010];//最后的结果数组int vis[1000010];//标记是否出现过,存储的是第一次出现的位置kint rec[1000010];//第k次出现时,被除数a的值int main(){ int a,b; while(~scanf("%d%d",&a,&b)) { memset(vis,0,sizeof(vis)); memset(rec,0,sizeof(rec)); printf("%d/%d = %d",a,b,a/b); a=a%b; int k=1; while(!vis[a]&&a)//如果访问过了,说明是循环小数,否则存在不循环的解 { vis[a]=k; rec[k]=a; a=a*10; rm[k++]=a/b; a=a%b; } printf("."); for(int i=1;i<k&&i<=50;++i) { if(a&&a==rec[i])//当从这个数开始循环的时候再加括号,只扩出循环部分 printf("("); printf("%d",rm[i]); } if(!a) printf("(0"); if(k>50) printf("..."); printf(")\n"); printf(" %d = number of digits in repeating cycle\n",a?(k-vis[a]):1);//k减去循环起始位置 } return 0;}
阅读全文
0 0
- Codeforces Round #450 (Div. 2)+刘汝佳紫书3-8 (C语言整数模拟除法)
- Codeforces Round #346 (Div. 2) C模拟
- Codeforces Round #325 (Div. 2) C 模拟
- Codeforces Round #316 (Div. 2) C 模拟
- Codeforces Round #306 (Div. 2) C 模拟
- Codeforces Round #126 (Div. 2) C 模拟
- Codeforces Round #373 (Div. 2) C 模拟
- Codeforces Round #377 (Div. 2) C 模拟
- C. Replacement( Codeforces Round #316 (Div. 2) 模拟)
- Codeforces Round #316 (Div. 2) C. Replacement (模拟)
- Codeforces Round #340 (Div. 2)(C)贪心,模拟
- Codeforces Round #321 (Div. 2)(C)模拟,DFS
- Codeforces Round #303 (Div. 2)-C. Woodcutters(模拟)
- Codeforces Round #350 (Div. 2)(C)模拟
- Codeforces Round #355 (Div. 2)C(模拟)
- Codeforces Round #357 (Div. 2) C Heap Operations(模拟)
- Codeforces Round #366 (Div. 2) C. Thor (模拟)
- Codeforces Round #366 (Div. 2) C. Thor(模拟)
- 如何降低在 npm 模块中发布敏感信息的可能性
- Linux系统下Libinput驱动的应用(主要在触摸屏校准)
- Android 自定义CheckBox样式
- MacOS Navicat Premium v10.1.1 for Mac 破解版
- MySql-创建触发器
- Codeforces Round #450 (Div. 2)+刘汝佳紫书3-8 (C语言整数模拟除法)
- 偏门套路:每天被动吸引150+精准淘宝粉
- 强化学习(Reinforcement Learning)
- ArrayList集合
- Angular中,数据更改自动加载页面
- Android 屏幕适配相关知识
- oracle重置表空间大小
- grep小结
- C++中函数重载、隐藏、覆盖和重写的区别 转自:http://www.bijishequ.com/detail/277975?p=