Codeforces 1159A A pile of stones
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                Codeforces 1159A  A pile of stones
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                題目鏈接:http://codeforces.com/problemset/problem/1159/A
題意:初始石頭堆石子數未知,求進行 n 次加減操作后,石頭堆石子數最小的可能是多少。
思路:正常模擬就好了,題意理解了老半天orz! 開始數量未知,所以模擬的答案是負數的話,最小可能就是0。
?AC代碼:
1 #include<iostream> 2 #include<algorithm> 3 #include<string> 4 using namespace std; 5 int main() 6 { 7 int n; 8 char a; 9 cin >> n ; 10 int ans = 0; 11 for(int i = 0;i < n;i++) 12 { 13 cin >> a; 14 if(a == '+') ans++; 15 else if(ans > 0)ans--; 16 } 17 cout << max(ans,0) << endl; 18 return 0; 19 }?
轉載于:https://www.cnblogs.com/Carered/p/10958213.html
總結
以上是生活随笔為你收集整理的Codeforces 1159A A pile of stones的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 第二阶段 冲刺十
- 下一篇: JavaScript原始类型转换和进制转
