zoukankan      html  css  js  c++  java
  • QFNU-ACM 2020.11.6 Trating

    D

    题意:就是根据题意画出那样的图形

    题解:因为n给了1-9所以可以使用打表,不然的话就是遍历然后输入空格,慢慢遍历就可,注意结尾没有空格。

    题解:

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
        int n;
        int count1=0;
        cin>>n;
        for(int i=1;i<=n+1;i++){
            int count=-1;
            for(int j=0;j<=n-i;j++){
                cout<<"  ";
            } 
            for(int j=0;j<i*2-1;j++){
                if(j>=i){
                    count--;
                    if(count==0){
                        cout<<count;
                    }
                    else{
                        cout<<count<<" ";
                    }
                }
                else{
                    count++;
                    if(i==1){
                        cout<<count;
                    }
                    else{
                        cout<<count<<" ";    
                    }    
                }
            }
            cout<<endl;
        }
        for(int i=n;i>=1;i--){
            int count=-1;
            for(int j=0;j<=n-i;j++){
                cout<<"  ";
            } 
            for(int j=0;j<i*2-1;j++){
                if(j>=i){
                    count--;
                    if(count==0){
                        cout<<count;
                    }
                    else{
                        cout<<count<<" ";
                    }
                }
                else{
                    count++;
                    if(i==1){
                        cout<<count;
                    }
                    else{
                        cout<<count<<" ";    
                    }
                }
            }
            cout<<endl;
        }
    }

    7-11 彩虹瓶 (25分)

    题意:给定一个序列,要求按顺序把不同的颜色拿出来。

    题解:使用stack的知识,然后如果不是这个颜色就把他加入栈,不然就把这个颜色拿出来,最后判断栈里面的元素有没有箱子的长度少。

    代码:

    #include<iostream>
    #include<cstdio>
    #include<stack>
    using namespace std;
    int main(){
        int N,M,K;
        int a;
        scanf("%d %d %d",&N,&M,&K);
        while(K--){//如果插入的数跟开始一样就把开始的数++(因为取出来了)
        //再判断下面一个相不相等,不相等的话就break 
            stack<int> s1;
            int begin=1,flag=0;
            for(int j=0;j<N;j++){
                scanf("%d",&a);
                if(a==begin){  
                    begin++;
                    while(s1.size()){ 
                        if(s1.top() == begin){
                            s1.pop();
                            begin++;
                        }
                        else  break;
                    }
                }else{
                    s1.push(a);
                    if(s1.size()>M) flag=1;
                }
            }
            if(s1.size()==0&&flag==0) printf("YES
    ");
            else printf("NO
    ");
        }
        return 0;
    }
  • 相关阅读:
    转:常用svn命令
    如何识别网页类型(wap页面还是wise页面)
    [转]手机web HTML头信息解释和viewport meta标签解释
    网页正文抽取
    python 去除不可见的控制字符
    11_MySQL_分页查询
    10_MySQL DQL_子查询(嵌套的select)
    静态函数和实例化方法
    GET 和 POST 方法的区别
    C# .NET 开发心得
  • 原文地址:https://www.cnblogs.com/liyongqi/p/13982832.html
Copyright © 2011-2022 走看看