數字台階 代碼語言:c

來源:互聯網
上載者:User
文章目錄
  • 數字台階
數字台階時限:1000ms 記憶體限制:10000K  總時限:3000ms

描述:

從平面座標的(0,0)點開始,我們可以寫出所有的非負的整數0,1,2,。。。。。。。
例如1,2,和3分別寫在(1,1),(2,0),和(3,1)點,然後我們可以按這種格式繼續寫出所有的數字:

現在需要你寫出一個程式讀入座標點(x,y),判斷該點出的數字為多少(如果有點的話),(x,y)均為0到5000之間的數字。

輸入:

輸入的第一行是數字N(N<1000), 表示為測試資料的個數。接下來將有N有測試資料,每行將有
兩個數字,分別代表x和y,既座標(x,y)的位置。

輸出:

對於每一行輸入的x和y,輸出該點的數字,每行一個。如果該點沒有數字,列印 No Number.

輸入範例:

3
4 2
6 6
3 4

輸出範例:

6
12
No Number

提示:

 

來源:

2006西北工業大學程式設計競賽決賽題E

 

代碼:

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main()
  4. {
  5. int n;
  6. int i,j;
  7. scanf("%d",&n);
  8. int **a;
  9. a=(int **)malloc(n*sizeof(int *));
  10. for(i=0; i<n; i++)
  11. {
  12. a[i]=(int *)malloc(2*sizeof(int));
  13. }
  14. for(i=0; i<n; i++)
  15. {
  16. for(j=0; j<2; j++)
  17. {
  18. scanf("%d",&a[i][j]);
  19. }
  20. }
  21. for(i=0; i<n; i++)
  22. {
  23. if(a[i][0]%2==0&&a[i][1]%2==0)
  24. printf("%d\n",a[i][0]+a[i][1]);
  25. else if(a[i][0]%2!=0&&a[i][1]%2!=0)
  26. printf("%d\n",a[i][0]+a[i][1]-1);
  27. else
  28. printf("No Number\n");
  29. }
  30. return 0;
  31. }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.