記 輸入輸出測試 7

2021-09-27 12:20:13 字數 804 閱讀 6540

描述

輸入 n 個數字,輸出數字 1 的數量 + 數字 0 的數量。

輸入第一行是乙個正整數 n 代表數字的數量。

第二行是 n 個非負整數,這些數字兩兩之間以空格分開。

輸出數字 1 的數量 + 數字 0 的數量,然後換行。

樣例輸入

50 1 2 3 4

樣例輸出

2初始自己瞎寫版:

#include

using

namespace std;

intmain()

if(i > n)

break;}

cout << cnt

}

更漂亮的寫法(for語句):

#include

using

namespace std;

intmain()

cout << cnt1 + cnt0 << endl;

return0;

}

①在知道迴圈次數的時候,用for語句更方便簡潔;

②p++可以改變自變數的值!

改良版:

#include

using

namespace std;

intmain()

} cout << cnt << endl;

//注意輸出個數的位置,以及cnt初始化位置

return0;

}

7 輸入輸出

str.format print format 1,2 212 print format name ji age 22 ji,22 print format 0,1,2 2,0 print format 陳某某 居中 print format 陳某某 右對齊 print format 陳某某 左對齊...

acm 輸入輸出測試

1 巧用 scanf 當沒告訴你輸入幾個時 直接輸入一串數字,以空格分開,換行結束 int a maxn int n char c while scanf d c a n,c c n n 2 當沒告訴你有幾組資料時,只告訴你 每組資料的結束標誌,程式的結束標誌時 要採取順序結構的思想,while 判...

7 HDFS輸入輸出流

hdfs的輸入輸出流用於對hdfs檔案進行位元組的讀取或寫入。把windows本地檔案通過hdfs的輸出流寫到hdfs檔案中。test public void testhdfsiooutput throws ioexception,interruptedexception,urisyntaxexce...