牛旅客機試験問題2
2715 ワード
1.タイトル記述機能:正の整数を入力し、そのすべての素数の因子(例えば180の素数因子が2 2 2 3 5)を小さい順に出力する.
入力記述:long型整数出力記述を入力します.すべての質量数の因子を小さい順から大きい順に出力し、スペースで区切ります.最後の数の後ろにもスペースが必要です
2.タイトル記述は、正の浮動小数点数値を受け入れ、その数値の近似整数値を出力するプログラムを書く.小数点以下の数値が5以上の場合は、上に整数を取ります.5未満の場合は、下に整列します.入力説明:正の浮動小数点数値出力説明を入力します:この数値の近似整数値を出力します
3.タイトル記述データテーブルレコードはテーブルインデックスと数値を含む(int範囲の整数)表索引の同じレコードをマージし、同じ索引の数値を加算し、key値の昇順で出力します.入力説明:キー値ペアの個数を入力してから、ペアのindexとvalue値を入力し、出力説明:マージ後のキー値ペア(複数行)を出力します
4.タイトル記述はint型整数を入力し、右から左への読み順に、重複数を含まない新しい整数を返します.入力説明:int型整数出力説明を入力します.右から左への読み取り順に、重複数を含まない新しい整数を返します.
5.タイトル記述は、文字列に含まれる異なる文字の個数を計算する関数を記述する.文字はACSIIコード範囲(0~127)で、改行は終了文字を表し、文字には含まれません.範囲外の統計はしない.説明を入力:ACSIIコード範囲内のN文字を入力します.出力説明:出力範囲が(0~127)文字の個数.
入力記述:long型整数出力記述を入力します.すべての質量数の因子を小さい順から大きい順に出力し、スペースで区切ります.最後の数の後ろにもスペースが必要です
#include
#include
#include
using namespace std;
string getResult(long ulDataInput);
int main()
{
long int ulDataInput;
cin >> ulDataInput;
cout << getResult(ulDataInput);
return 0;
}
string getResult(long ulDataInput)
{
string s = "";
bool isPrime = true;
int i = 2;
for (; i <= sqrt(ulDataInput); ++i)
{
if (0 == (ulDataInput % i))
{
isPrime = false;
break;
}
}
if (isPrime)
return s += to_string(ulDataInput) + " ";
else
return getResult(i) + getResult(ulDataInput / i);
}
2.タイトル記述は、正の浮動小数点数値を受け入れ、その数値の近似整数値を出力するプログラムを書く.小数点以下の数値が5以上の場合は、上に整数を取ります.5未満の場合は、下に整列します.入力説明:正の浮動小数点数値出力説明を入力します:この数値の近似整数値を出力します
#include
#include
using namespace std;
int main(){
float num;
cin>>num;
cout<
3.タイトル記述データテーブルレコードはテーブルインデックスと数値を含む(int範囲の整数)表索引の同じレコードをマージし、同じ索引の数値を加算し、key値の昇順で出力します.入力説明:キー値ペアの個数を入力してから、ペアのindexとvalue値を入力し、出力説明:マージ後のキー値ペア(複数行)を出力します
#include
#include
4.タイトル記述はint型整数を入力し、右から左への読み順に、重複数を含まない新しい整数を返します.入力説明:int型整数出力説明を入力します.右から左への読み取り順に、重複数を含まない新しい整数を返します.
#include
using namespace std;
int main()
{
int n;
int a[10] = { 0 };
int num = 0;
cin >> n;
while (n)
{
if (a[n % 10] == 0)
{
a[n % 10]++;
num = num * 10 + n % 10;
}
n /= 10;
}
cout << num << endl;
return 0;
}
5.タイトル記述は、文字列に含まれる異なる文字の個数を計算する関数を記述する.文字はACSIIコード範囲(0~127)で、改行は終了文字を表し、文字には含まれません.範囲外の統計はしない.説明を入力:ACSIIコード範囲内のN文字を入力します.出力説明:出力範囲が(0~127)文字の個数.
#include
#include
using namespace std;
int main()
{
char c;
set s;
while(cin>>c){
if(c>=0 && c<=127){
s.insert(c);
}
}
cout << s.size() <