1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
#include <iostream> #include <cstdio> using namespace std; int arr[10005]; int n; int Search(int num) { int i=1; while(i<=n) { if(arr[i]==num) return i; i++; } } /* 5 5 5 1 3 2 4 9 4 5 1 2 6 3 8 9 7 //Case 1/2: 3/6 */ int main() { int t,nxtIdx,kase=1; cin>>t; while(t--) { cin>>n; for(int i=1;i<=n;i++) cin>>arr[i]; int lastIdx=0; int sortBreakingNumber=0; for(int i=1;i<=n;i++) { nxtIdx = Search(i); if(nxtIdx<lastIdx) { sortBreakingNumber=i; break; } lastIdx=nxtIdx; } if(sortBreakingNumber==0) cout<<"Case "<<kase++<<": "<<0<<"\n"; else cout<<"Case "<<kase++<<": "<<(n-sortBreakingNumber+1)<<"\n"; } return 0; } |