我試圖調試我的C++程序的標準輸入作爲C++向量輸入 - 運行時錯誤 - 調試超時 - 第一個for循環失敗
2 1 /newline/
4
輸出調試器(onlinegdb)的: - 雖然第二行讀取了另一組由問題提供的輸入;此時,向量arr未顯示輸出4 set args 讀取/home/a.out...done中的符號。 (gdb)繼續
程序未運行。
(GDB)運行
Starting program: /home/a.out </home/input.txt
2 1
P.S. The program successfully compiles and runs for user provided input
3 2
3
4
P.S.那麼,爲什麼程序中的第一個循環並沒有正確執行?
源代碼 -
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int m;
cin>>m;
int t;
cin>>t;
cout<<m<<" "<<t<<"\n";
int sum=0;
vector<int> arr(t);
for(int i=0;i<t;i++)
cin>>arr[i]; //arr[i]=k digit nos
for(int i=0;i<t;i++)
cout<<arr[i]<<" ";
int comb(int a, int b); //6,2
for(int i=0;i<t;i++)
{
if(m==arr[i]){
cout<<m<<" a "<<9*pow(10,m-1)<<"\n";
}
if(m>arr[i]){
cout<<m<<" b "<<9*pow(10,m-1)<<"\n";
}
if(m<arr[i]){
/*if(m==arr[i]-1){
cout<<m<<" c "<<9*pow(10,arr[i]-1)-9<<"\n";
}
else{*/
sum=pow(10,arr[i])-1;
for(int j=arr[i]-1;j>m;j++)
sum=sum-comb(arr[i],j)*pow(9,arr[i]-j+1);
cout<<" d "<<sum<<"\n";
//}
}
}
//for m upto 10^4, k<=10^5; else k=10^5
return 0;
}
int comb(int a, int b) { //6,2
int j=1;
int s=a;
for(int k=a-1;k>b;k--) //5,4,3
s=s*k;
for(int l=1;l<=b;l++)
s=s/l;
return s;
}
//It is a problem involving displaying number of integers with no digit //repeating more than m (=2 here) times for t(=1) inputs with each input //being a arr[i] (=4) digit number.