#include <iostream>
using namespace std;
int main(){
int array_size, array[100];
cout << "Enter length of number you want to input ";
cin >> array_size;
cout << "Enter the inputs" << endl;
for (int i = 0; i < array_size; i++){
cin >> array[i];
if (array[i] == 0){
array[i] = 1;
}else{
array[i] = 0;
}
}
cout << "output" << endl;
for (int i = 0; i < array_size; i++){
cout << array[i];
}
cout << endl;
system("PAUSE");
return 0;
}
答案 0 :(得分:1)
读取字符串的输入并解析该字符串中的数字。
std::string input;
std::cin >> input;
for (int i = 0; i < array_size; i++){
if (input.at(i) == '0') {
array[i] = 1;
} else {
array[i] = 0;
}
}