题目链接:http://codeforces.com/problemset/problem/616/A

题目意思:顾名思义,就是比较两个长度不超过 1e6 的字符串的大小

模拟即可。提供两个版本,数组版本 & 指针版本。

  (1)数组版本(短的字符串从高位处补0,直到跟长的字符串长度相同)

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxn = 1e6 + ;
char a[maxn], b[maxn];
int rev_a[maxn], rev_b[maxn]; int cmp(int len)
{
int f = ; // 0: a=b; 1: a>b; 2: a<b
// 比较的时候要从高位比起,存储的时候是从低位开始存的
for (int i = len-; i >= && !f; i--) {
if (rev_a[i] > rev_b[i]) {
f = ;
}
else if (rev_a[i] < rev_b[i]) {
f = ;
}
}
return f;
} int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE while (scanf("%s%s", a, b) != EOF) {
int la = strlen(a);
int lb = strlen(b); for (int i = ; i < la; i++) {
rev_a[la-i-] = a[i]-'';
} for (int i = ; i < lb; i++) {
rev_b[lb-i-] = b[i]-'';
} int flag = ;
// 保证比较的字符串长度相等, 0补上
if (la < lb) { // la < lb
for (int i = ; i < lb-la; i++) {
rev_a[la+i] = ;
}
flag = cmp(lb);
}
else { // la >= lb
for (int i = ; i < la-lb; i++) {
rev_b[lb+i] = ;
}
flag = cmp(la);
}
if (flag == ) puts(">");
else if (flag == ) puts("<");
else puts("=");
}
return ;
}

  (2)指针版本(过滤前缀0之后,再逐位比较大小)

 /*
指针版本
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxn = 1e6 + ;
char a[maxn], b[maxn]; int cmp(char *s1, char *s2)
{
// 过滤前缀 0
while (*s1 == '') {
s1++;
}
while (*s2 == '') {
s2++;
} int l1 = strlen(s1);
int l2 = strlen(s2);
if (l1 > l2) {
return '>';
}
else if (l1 < l2) {
return '<';
}
// a,b长度相等(l1 = l2)
for (int i = ; i < l1; i++) {
if (*s1 < *s2) { // 指针指向的值
return '<';
}
else if (*s1 > *s2) {
return '>';
}
s1++; // 指针右移一位
s2++;
}
return '=';
} int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE while (scanf("%s%s", a, b) != EOF) {
printf("%c\n", cmp(a, b));
}
return ;
}

codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers的更多相关文章

  1. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  2. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  3. Codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers 高精度比大小,模拟

    A. Comparing Two Long Integers 题目连接: http://www.codeforces.com/contest/616/problem/A Description You ...

  4. Educational Codeforces Round 5 A. Comparing Two Long Integers

    A. Comparing Two Long Integers time limit per test 2 seconds memory limit per test 256 megabytes inp ...

  5. codeforces Educational Codeforces Round 16-E(DP)

    题目链接:http://codeforces.com/contest/710/problem/E 题意:开始文本为空,可以选择话费时间x输入或删除一个字符,也可以选择复制并粘贴一串字符(即长度变为两倍 ...

  6. Codeforces Educational Codeforces Round 15 E - Analysis of Pathes in Functional Graph

    E. Analysis of Pathes in Functional Graph time limit per test 2 seconds memory limit per test 512 me ...

  7. Codeforces Educational Codeforces Round 15 D. Road to Post Office

    D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...

  8. Codeforces Educational Codeforces Round 15 C. Cellular Network

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  9. Codeforces Educational Codeforces Round 5 E. Sum of Remainders 数学

    E. Sum of Remainders 题目连接: http://www.codeforces.com/contest/616/problem/E Description The only line ...

随机推荐

  1. sql中的常见的全局变量

    select APP_NAME ( ) as w --当前会话的应用程序 select @@IDENTITY --返回最后插入的标识值 select USER_NAME() --返回用户数据库用户名 ...

  2. [译]git log

    git log git log命令用来显示提交的快照. 能列出来你项目的历史, 能过滤和搜索你指定的一些修改. git status能让你检查工作目录和stage区的状态, git log只提供被co ...

  3. Linux中postfix邮件服务器的搭建

    postfix是Wietse Venema在IBM的GPL协议之下开发的MTA(邮件传输代理)软件.postfix是Wietse Venema想要为使用最广泛的sendmail提供替代品的一个尝试.在 ...

  4. UIGestureRecognizer

    •为了完成手势识别,必须借助于手势识别器----UIGestureRecognizer • •利用UIGestureRecognizer,能轻松识别用户在某个view上面做的一些常见手势 • •UIG ...

  5. 郝斌C语言代码

    #include<stdio.h> int main() { ; printf("%#x\n",a); ; } /* output 0xf; */ //(15)10= ...

  6. Linux下运行C语言程序

    一.编写C语言的源代码 二.用gcc -c C文件名生成.o文件 三.用gcc -o 可执行文件名 .o文件名 生成可执行文件 四.输入可执行文件名前加./执行可执行文件

  7. XML文件数据操作

    #region XML序列化文件和反序列化 /// <summary> /// 通用类的保存函数,可以将已经声明过可序列化的类以文件方式保存起来. /// 保存格式分为 XML明文式和 二 ...

  8. tomcat JNDI 设置

    一.在Spring配置文件中的配置   <bean id="dataSource" class="org.springframework.jndi.JndiObje ...

  9. 淘宝(阿里百川)手机客户端开发日记第十五篇 JSON解析(四)

    解析一个从淘宝传递的JSON (大家如有兴趣可以测试下):{ "tae_item_detail_get_response": { "data": { " ...

  10. TP5的图片上传

    public function upload(){ // 获取表单上传文件 例如上传了001.jpg $file = request()->file('image'); $picture=mod ...