题目链接: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. Java字节流:FileInputStream FileOutputStream

    ----------------------------------------------------------------------------------- FileInputStream ...

  2. MYSQL 连接数据库命令收藏

    一.MySQL 连接本地数据库,用户名为“root”,密码“123”(注意:“-p”和“123” 之间不能有空格) C:\>mysql -h localhost -u root -p123 二. ...

  3. 系统研究Airbnb开源项目airflow

    开源项目airflow的一点研究 调研了一些几个调度系统, airflow 更满意一些. 花了些时间写了这个博文, 这应该是国内技术圈中最早系统性研究airflow的文章了.  转载请注明出处 htt ...

  4. iOS开发——项目需求-快速回到当前界面的顶部

    利用UIWindow实现快速到达顶部 如下图,在状态栏添加一个没有颜色的UIWindow(里面添加一个按钮),实现点击这个按钮时能快速的回到当前界面的顶部 核心代码 一.利用UIWindow实现到达顶 ...

  5. [POJ1177]Picture

    [POJ1177]Picture 试题描述 A number of rectangular posters, photographs and other pictures of the same sh ...

  6. caffe学习系列(7):Blob,layer,Net介绍

    参考:http://www.cnblogs.com/denny402/p/5073427.html

  7. Android_bug之 task ':app:mergeDebugResources'. > Some file crunching failed, see logs f

    今天调试安卓程序遇到的问题Error:Execution failed for task ':app:mergeDebugResources'. > Some file crunching fa ...

  8. 解压.tar.gz出错gzip: stdin: not in gzip format tar: /Child returned status 1 tar: Error is not recoverable: exiting now

    先查看文件真正的属性是什么? [root@xxxxx ~]# tar -zxvf tcl8.4.16-src.tar.gz  gzip: stdin: not in gzip format tar: ...

  9. 线程池大小 & cpu core

    http://stackoverflow.com/questions/14556037/number-of-processor-core-vs-the-size-of-a-thread-pool ht ...

  10. python对象的生命周期

    引言 碰到以下问题: 代码1: from Tkinter import * root = Tk() photo = PhotoImage(file=r'E:\workspace\python\111. ...