csu 1777
来源:互联网 发布:淘宝店铺页面装修图 编辑:程序博客网 时间:2024/05/17 22:28
1777: 大还是小?
Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 810 Solved: 303 Description
输入两个实数,判断第一个数大,第二个数大还是一样大。每个数的格式为:
[整数部分].[小数部分]
简单起见,整数部分和小数部分都保证非空,且整数部分不会有前导 0。不过,小数部分的最 后可以有 0,因此 0.0 和 0.000 是一样大的。
Input
输入包含不超过 20 组数据。每组数据包含一行,有两个实数(格式如前所述)。每个实数都 包含不超过 100 个字符。
Output
对于每组数据,如果第一个数大,输出"Bigger"。如果第一个数小,输出"Smaller"。如果两个 数相同,输出"Same"。
Sample Input
1.0 2.00.00001 0.000000.0 0.000
Sample Output
Case 1: SmallerCase 2: BiggerCase 3: Same
Hint
Source
湖南省第十一届大学生计算机程序设计竞赛
这个题目我竟然做了这么久 我有点怀疑人生了!!!
#include<iostream> #include<cstdio> #include<cstring> using namespace std; char a[101],b[101]; int flag; void f() { flag=0; int i; int sa=strlen(a); int sb=strlen(b); for(i=0; i<sa&&i<sb; i++) { if(a[i]=='.') { if(b[i]!='.')//a<b的时候 { flag=-1; return; } if(flag) return; } if(a[i]!='.'&&b[i]=='.')//a>b的时候 { flag=1; return ; } if(flag==0) flag=a[i]-b[i];//小数点的位置相同的时候,判断相同位置的数的大小 } if(flag) return ; while(i<sa)//如果两个数长度相同的位置都相等,那么就比较剩下的数,是否为零或者大于零 { flag+=a[i++]-'0'; } while(i<sb) { flag-=b[i++]-'0'; } } int main() { int cas = 1; while (cin >> a >> b) { cout << "Case " << cas++ << ": "; f(); if (flag > 0)cout << "Bigger"; else if (flag < 0)cout << "Smaller"; else cout << "Same"; cout << endl; } return 0; }
阅读全文
0 0
- csu 1777
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- OpenGL 笔记(二) 图元的属性
- 欢迎使用CSDN-markdown编辑器
- 100. Same Tree
- MySQL删除重复记录
- runable和thread的区别
- csu 1777
- python 连接 mongodb pymongo.Connection 不能用
- Vue+WebPack游戏设计:自动背景贴图和游戏主循环的实现
- 2018滴滴校招(秋招)内推笔试编程题题解
- 单机多实例MYSQL主从复制
- 同敏捷前辈聊天的一些记录
- python的变量以及类型
- CORS——跨域请求那些事儿
- webstore破解