程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> ZOJ 3465 The Hive 暴力模擬

ZOJ 3465 The Hive 暴力模擬

編輯:C++入門知識

[cpp] 
//ZOJ 3465 The Hive 
//暴力模擬 
#include<iostream> 
#include<stdio.h> 
#include<stack> 
using namespace std; 
#define N 10 
 
int n; 
char s[N]; 
stack<char>S[N]; 
int arr[N] = {0,7,8,9,10,11,10,9,8,7}; 
 
void init(){ 
    int i; 
    for(i = 1; i <= 9; ++i) 
        while(!S[i].empty()) 
            S[i].pop(); 

 
char bx(int i,int j){//判斷第i列的第j個元素是否存在 存在返回該值並出棧 否則返回‘’ 
    char c = 32; 
    if(S[i].size() == j){ 
        c = S[i].top(); 
        S[i].pop(); 
    } 
    return c; 

 
void print(){ 
    printf("         _");printf("\n"); 
    printf("       _/%c\\_",bx(5,11));printf("\n"); 
    printf("     _/%c\\_/%c\\_",bx(4,10),bx(6,10));printf("\n"); 
    printf("   _/%c\\_/%c\\_/%c\\_",bx(3,9),bx(5,10),bx(7,9));printf("\n"); 
    printf(" _/%c\\_/%c\\_/%c\\_/%c\\_",bx(2,8),bx(4,9),bx(6,9),bx(8,8));printf("\n"); 
 
    printf("/%c\\_/%c\\_/%c\\_/%c\\_/%c\\",bx(1,7),bx(3,8),bx(5,9),bx(7,8),bx(9,7));printf("\n"); 
    printf("\\_/%c\\_/%c\\_/%c\\_/%c\\_/",bx(2,7),bx(4,8),bx(6,8),bx(8,7));printf("\n"); 
    printf("/%c\\_/%c\\_/%c\\_/%c\\_/%c\\",bx(1,6),bx(3,7),bx(5,8),bx(7,7),bx(9,6));printf("\n"); 
    printf("\\_/%c\\_/%c\\_/%c\\_/%c\\_/",bx(2,6),bx(4,7),bx(6,7),bx(8,6));printf("\n"); 
    printf("/%c\\_/%c\\_/%c\\_/%c\\_/%c\\",bx(1,5),bx(3,6),bx(5,7),bx(7,6),bx(9,5));printf("\n"); 
    printf("\\_/%c\\_/%c\\_/%c\\_/%c\\_/",bx(2,5),bx(4,6),bx(6,6),bx(8,5));printf("\n"); 
    printf("/%c\\_/%c\\_/%c\\_/%c\\_/%c\\",bx(1,4),bx(3,5),bx(5,6),bx(7,5),bx(9,4));printf("\n"); 
    printf("\\_/%c\\_/%c\\_/%c\\_/%c\\_/",bx(2,4),bx(4,5),bx(6,5),bx(8,4));printf("\n"); 
    printf("/%c\\_/%c\\_/%c\\_/%c\\_/%c\\",bx(1,3),bx(3,4),bx(5,5),bx(7,4),bx(9,3));printf("\n"); 
    printf("\\_/%c\\_/%c\\_/%c\\_/%c\\_/",bx(2,3),bx(4,4),bx(6,4),bx(8,3));printf("\n"); 
    printf("/%c\\_/%c\\_/%c\\_/%c\\_/%c\\",bx(1,2),bx(3,3),bx(5,4),bx(7,3),bx(9,2));printf("\n"); 
    printf("\\_/%c\\_/%c\\_/%c\\_/%c\\_/",bx(2,2),bx(4,3),bx(6,3),bx(8,2));printf("\n"); 
    printf("/%c\\_/%c\\_/%c\\_/%c\\_/%c\\",bx(1,1),bx(3,2),bx(5,3),bx(7,2),bx(9,1));printf("\n"); 
    printf("\\_/%c\\_/%c\\_/%c\\_/%c\\_/",bx(2,1),bx(4,2),bx(6,2),bx(8,1));printf("\n"); 
 
    printf("  \\_/%c\\_/%c\\_/%c\\_/",bx(3,1),bx(5,2),bx(7,1));printf("\n"); 
    printf("    \\_/%c\\_/%c\\_/",bx(4,1),bx(6,1));printf("\n"); 
    printf("      \\_/%c\\_/",bx(5,1));printf("\n"); 
    printf("        \\_/");printf("\n"); 
 

 
 
int main(){ 
    int i,ans; 
    while(gets(s)!=NULL){ 
        sscanf(s,"%d",&n); 
        init(); 
        ans = 0; 
        for(i = 1; i <= n; ++i){ 
            gets(s); 
            int index = s[0]-'A'+1; 
            if(!S[index].empty() && S[index].size()<arr[index]  && S[index].top() == s[1]){ 
                S[index].pop(); 
                ans++; 
            } 
            else if(S[index].size() <  arr[index]){ 
                S[index].push(s[1]); 
            } 
        } 
        printf("The number of candy is %d.\n",ans); 
        print(); 
    } 
    return 0; 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved