L1-2 6翻了 (15分)

在这里插入图片描述

it is so 666 really 6666 what else can I say 6666666666

输出样例:

it is so 666 really 9 what else can I say 27

扫描 不是6就直接输出 遇到6停止扫描进行个数num统计 直到碰到再次不是6的数字进行输出 但在此之前先输出6的格式变换输出 具体格式转化就看题就行 不难理解
注意的就是 for(int I = 0;) I要初始化 要不各种错误 枯了 今天真的碰到好多这种容易被忽略但是一卡一个准的点 害
AC代码

#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

int main()
{
    
    
    string s;
    getline(cin, s);
    int len = s.length();
    for(int i = 0; i < len; )
    {
    
    
    	if(s[i] != '6') 
    		{
    
    
    			cout << s[i];
    			i++;
    		}
    	else
    	{
    
    
    		int num = 0;
    		while(s[i] == '6')
    		{
    
    
    			num++;
    			i++;
    		}
    		if(num > 3 && num <= 9) cout << "9";
    		else if(num > 9) cout << "27";  
    		else 
    		{
    
    
    			while(num--) cout << "6";
    		}
    	}
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/moumoumouwang/article/details/109662637