杭电oj 1002 wrong answer(待改正)

/*#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){

int n;
int i,j,q;//计数
int al=0;
int bl=0;
int cl,dl;
char turn;
char a[1001];
char b[1001];
char c[1002];
int sum[1002];
for(i=0;i<1001;i++){
sum[i]=a[i]=b[i]=c[i]=‘0‘;
}
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%s %s",a,b);
printf("Case %d:\n",i);
printf("%s + %s = ",a,b);

al=strlen(a);
bl=strlen(b);
cl=al>bl?al:bl;
for(j=0,q=al;j<q-1;j++,q--){
turn=a[j];
a[j]=a[q-1];
a[q-1]=turn;
}
for(j=0,q=bl;j<q-1;j++,q--){
turn=b[j];
b[j]=b[q-1];
b[q-1]=turn;
}

for(j=al;j<cl;j++){
a[j]=‘0‘;
}
for(j=bl;j<cl;j++){
b[j]=‘0‘;
}
for(j=0;j<cl;j++){
if(a[j]+b[j]-‘0‘-‘0‘>9)
c[j+1]=‘1‘;
sum[j]=(a[j]+b[j]+c[j]-‘0‘-‘0‘-‘0‘)%10;

}

if(c[cl]==‘1‘)
printf("1");

for(j=cl-1;j>=0;j--){
printf("%d",sum[j]);

}
if(i!=n)
printf("\n\n");

}

}
*/

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){

int n;
int i,j,q;//计数
int al=0;
int bl=0;
int cl,dl;
char turn;
char a[1001];
char b[1001];
char c[1002];
int sum[1002];
for(i=0;i<1001;i++){
sum[i]=a[i]=b[i]=c[i]=‘0‘;
}
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%s %s",a,b);

al=strlen(a);
bl=strlen(b);
cl=al>bl?al:bl;
for(j=0,q=al;j<q-1;j++,q--){
turn=a[j];
a[j]=a[q-1];
a[q-1]=turn;
}
for(j=0,q=bl;j<q-1;j++,q--){
turn=b[j];
b[j]=b[q-1];
b[q-1]=turn;
}

for(j=al;j<cl;j++){
a[j]=‘0‘;
}
for(j=bl;j<cl;j++){
b[j]=‘0‘;
}
for(j=0;j<cl;j++){
if(a[j]+b[j]-‘0‘-‘0‘>9)
c[j+1]=‘1‘;
sum[j]=(a[j]+b[j]+c[j]-‘0‘-‘0‘-‘0‘)%10;

}

printf("Case %d:\n",i);
for(j=al-1;j>=0;j--)
printf("%c",a[j]);
printf(" + ");
for(j=bl-1;j>=0;j--)
printf("%c",b[j]);
printf(" = ");
if(c[cl]==‘1‘)
printf("1");

for(j=cl-1;j>=0;j--){
printf("%d",sum[j]);

}
if(i!=n)
printf("\n\n");

}

system("pause");

}

时间: 2024-08-09 03:43:25

杭电oj 1002 wrong answer(待改正)的相关文章

杭电oj 1002

1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 int nCases; 5 int m[1001], n[1001]; 6 char a[1001], b[1001]; 7 int main() 8 { 9 scanf("%d", &nCases); 10 for(int i = 1; i <= nCases; ++i) 11 { 12 memset(m,

杭电OJ 1002 大数相加

Problem Description I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B. Input The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines fol

【转】对于杭电OJ题目的分类

[好像博客园不能直接转载,所以我复制过来了..] 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDI

杭电oj 1009 FatMouse&#39; Trade

Tips:本题采用贪心算法,类似于背包问题,关键在于读入数据之后,将数据按 J[i]/F[i] 从大到小排列即可. 1 /**本程序主要采用贪心算法思想,类似于背包问题*/ 2 #include<stdio.h> 3 #include<string.h> 4 int main() 5 { 6 int M,N; 7 while(scanf("%d %d",&M,&N)) 8 { 9 if(M == -1 && N == -1) 10

异或^符号在C/C++中的使用 &amp; 杭电oj 2095

异或^符号,在平时的学习时可能遇到的不多,不过有时使用得当可以发挥意想不到的结果. 值得注意的是,异或运算是建立在二进制基础上的,所有运算过程都是按位异或(即相同为0,不同为1,也称模二加),得到最终结果. 特点:任何数和0异或都等于它本身;两个相同的数异或后的结果是0: 举例如下: int a = 4 =100(二进制) int b = 3 =011(二进制) int c = a^b = 111 = 7: 下面就^常用应用做个介绍: 1. 在一排数中找到独一无二的一个数 本例启发来自于杭电oj

杭电OJ(HDU)-ACMSteps-Chapter Two-《An Easy Task》《Buildings》《decimal system》《Vowel Counting》

http://acm.hdu.edu.cn/game/entry/problem/list.php?chapterid=1§ionid=2 1.2.5 #include<stdio.h> /* 题意:找闰年. if((i%4==0 && i%100!=0) || i%400==0)count++; 3 2005 25 1855 12 2004 10000 2108 1904 43236 */ int main() { int t,y,n; int i,count=0; whil

杭电OJ(HDU)-ACMSteps-Chapter Three-《FatMouse&amp;#39; Trade》《今年暑假不AC》《排名》《开门人和关门人》

http://acm.hdu.edu.cn/game/entry/problem/list.php?chapterid=1§ionid=3 1.3.1 FatMouse' Trade #include <algorithm> /* 题意:价值/代价的比值来排序,买比值大的. Sample Input 5 3 7 2 4 3 5 2 20 3 25 18 24 15 15 10 -1 -1 Sample Output 13.333 31.500 */ #include<stdio.h>

杭电oj 1069 Monkey and Banana

Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6866 Accepted Submission(s): 3516 Problem Description A group of researchers are designing an experiment to test the IQ of a monkey

杭电OJ(HDU)-ACM Steps-Chapter Two-《Biker&#39;s Trip Odometer》《Climbing Worm》《hide handkerchief》《Nasty Hac》

1.2.1 Biker's Trip Odometer #include<stdio.h> #include<math.h> const double PI=acos(-1.0); /* 计算题,根据公式做就行,PI*d*r/(12*5280);res1/t*3600; Sample Input 26 1000 5 27.25 873234 3000 26 0 1000 Sample Output Trip #1: 1.29 928.20 Trip #2: 1179.86 1415