程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> 1001 A + B Problem,1001problem

1001 A + B Problem,1001problem

編輯:關於C語言

1001 A + B Problem,1001problem


基本輸入輸出函數

1 #include <stdio.h>
2 
3 int main(){
4     int a,b;
5     while(scanf("%d %d",&a,&b)>=0){
6         printf("%d\n",a+b);
7     }
8     return 0;
9 }

 


ZOJ Problem Set - 1001:A + B Problem的如下解答為何報錯?

#include<stdio.h>
int main()
{
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
printf("%d\n",a+b);
return 0;
}

主程序應返回int。
 

A + B Problem II - HDOJ 1002

#include <iostream>#include <cstring> using namespace std; char CA[1000],CB[1000];int IA[1001]; int main() { int n,m1 = 0,m2 = 0,c,s = 1,i,j,k,num; cin >> n; while(n--) { scanf("%s%s",CA,CB); m1 =strlen(CA); m2 = strlen(CB); c = 0; for(i = m1 - 1,j = m2 - 1,k = 0;j >= 0 && i >= 0;i--,j--,k++) { num = CA[i] - '0' + CB[j] - '0' + c; IA[k] = num % 10; c = num / 10; } if(j > i) { while(j >= 0) { num = CB[j] - '0' + c; IA[k] = num % 10; c = num / 10; k++,j--; } } else if(i > j) { while(i >= 0) { num = CA[i] - '0' + c; IA[k] = num % 10; c = num / 10; k++,i--; } } else if(c) IA[k++] = c; cout << "Case " << s << ":\n"; cout << CA << " + " << CB << " = "; for(i = k - 1;i >= 0;i--) cout << IA[i]; cout << endl; s++; } return 0;}
 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved