1164 Good in C

题目链接
注意点:
1.每行读取结束后还要再用getchar();读取换行符,否则会出错;
2.间隔符可能为空格,因此要用getline读取字符串;
3.读取每个单词时,最后一个单词末尾如果没有间隔符,是读取不到的,因此还要考虑i == str.size() - 1的情况,把单词添加上。

代码

#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;
const int maxn = 10010;
int main(){
    int Letter[26][7][5];
    for(int i = 0; i < 26; i++){
        for(int j = 0; j < 7; j++){
            for(int k = 0; k < 5; k++){
                char l;
                scanf("%c", &l);
                if(l == '.'){
                    Letter[i][j][k] = 0;
                }else{
                    Letter[i][j][k] = 1;
                }
            }
            getchar();
        }
        
    }
    string str, words[maxn];
    int count = 0;
    getline(cin, str);
    string temp = "";
    for(int i = 0; i < str.size(); i++){
        if(str[i] >= 'A' and str[i] <= 'Z'){
            temp += str[i];
            if(i == str.size() - 1){
            	words[count++] = temp;
			}
        }else{
            if(temp.size() != 0){
                words[count++] = temp;
            }
            temp = "";
        }
    }
    for(int i = 0; i < count; i++){
        string nowstr = words[i];
        for(int j = 0; j < 7; j++){
            for(int l = 0; l < nowstr.size(); l++){
                for(int k = 0; k < 5; k++){
                	int x = nowstr[l] - 'A';
                    if(Letter[x][j][k] == 1){
                        printf("%c", 'C');
                        
                    }else{
                        printf("%c", '.');
                    }
                    if(k == 4 and l < nowstr.size() - 1){
                        printf(" ");
                    }
                }
            }
            printf("\n");
        }
        if(i < count - 1){
            printf("\n");
        }
        
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值