首页 > 试题广场 >

抄送列表

[编程题]抄送列表
  • 热度指数:3356 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
NowCoder每天要处理许多邮件,但他并不是在收件人列表中,有时候只是被抄送。他认为这些抄送的邮件重要性比自己在收件人列表里的邮件低,因此他要过滤掉这些次要的邮件,优先处理重要的邮件。
现在给你一串抄送列表,请你判断目标用户是否在抄送列表中。

输入描述:
输入有多组数据,每组数据有两行。

第一行抄送列表,姓名之间用一个逗号隔开。如果姓名中包含空格或逗号,则姓名包含在双引号里。总长度不超过512个字符。

第二行只包含一个姓名,是待查找的用户的名字(姓名要完全匹配)。长度不超过16个字符。


输出描述:
如果第二行的名字出现在收件人列表中,则输出“Ignore”,表示这封邮件不重要;否则,输出“Important!”,表示这封邮件需要被优先处理。
示例1

输入

Joe,Kewell,Leon
Joe
"Letendre, Bruce",Joe,"Quan, William"
William

输出

Ignore
Important!
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while(in.hasNext()){
			String str=in.nextLine();
			String verStr=in.nextLine();
			char[] cA = str.toCharArray();
			int len=str.length();
			LinkedList<String> list=new LinkedList<String>();
			StringBuilder sb=new StringBuilder();
			int count=0;
			for (int i = 0; i < len; i++) {
				char c = cA[i];
				if(c=='"'){
					count++;
				}
				else{
					if(count==1){
						sb.append(c);
					}
					else if(count==0){
						if(c==','){
							list.add(sb.toString());
							sb=new StringBuilder();
						}
						else{
							sb.append(c);
						}
					}
				}
				
				if(count==2){
					list.add(sb.toString());
					sb=new StringBuilder();
					count=0;
					i++;//避免间隔符--逗号
				}
				else if(i==len-1){//最后一组不是引号组
					list.add(sb.toString());
				}
			}
			
			int size=list.size();
			String sArr[]=new String[size];
			for (int i = 0; i < size; i++) {
//				System.out.println(list.get(i));
				sArr[i]=list.get(i);
			}
			
			boolean flag=false;
			for (int i = 0; i < size; i++) {
				if(sArr[i].equals(verStr)){
					System.out.println("Ignore");
					flag=true;
					break;
				}
			}
			
			if(flag){
				continue;
			}
			else{
				System.out.println("Important!");
			}
		}
	}
}
发表于 2016-10-16 23:08:08 回复(0)
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s, res;
	while (getline(cin, s))
	{
		getline(cin, res);
		bool sta = false;
		for (int i = 0; i < s.length(); i++)
		{
			string t;
			if (s[i] == '"')
			{
				i++;
				while (i<s.length()&&s[i] != '"')
				{
					t += s[i];
					i++;
				}
				if (t == res)
				{
					sta = true;
					break;
				}
			}
			else if (s[i] != ',')
			{
				while (i<s.length()&&s[i] != ',')
				{
					t += s[i];
					i++;
				}
				if (t == res)
				{
					sta = true;
					break;
				}
			}
		}
		if (sta == true)
			cout << "Ignore" << endl;
		else
			cout << "Important!" << endl;
	}
	return 0;
}

发表于 2017-04-24 12:38:49 回复(1)
用哈希表记录名字,注意每次括号的内容
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<functional>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <exception>
#include <iomanip>
#include <memory>
#include <sstream>
#define INF 1000000
using namespace std;
int main(int argc, char** argv)
{
 //freopen("in.txt", "r", stdin);
 string s;
 while (getline(cin, s))
 {
  unordered_set<string> names;
  string name = "";
  bool inBracket = false;
  for (auto& c : s)
  {
   if (c == '\"')
   {
    inBracket = !inBracket;
   }
   else if (c == ',')
   {
    if (inBracket) name += c;
    else
    {
     names.emplace(name);
     name = "";
    }
   }
   else
   {
    name += c;
   }
  }
  names.emplace(name);
  getline(cin, name);
  cout << (names.find(name) != names.end() ? "Ignore" : "Important!") << endl;
 }
 return 0;
}

发表于 2017-07-19 10:37:32 回复(0)
题简单,就是代码还不少hhhhhhh
// write your code here cpp
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    string str,name;
    while(getline(cin,str))
    {
        getline(cin,name);
        //接下来把抄送列表分割
        vector<string>v;
        for(size_t i=0;i<str.size();i++)
        {
            if(str[i]=='\"'){//处理有引号的部分
                v.push_back(str.substr(i+1,str.find('\"',i+1)-i-1));
                i=str.find('\"',i+1)+1;
            }
            else{//处理非引号部分
                if(str.find(',',i)==str.npos){
                    v.push_back(str.substr(i,str.size()-i));
                    i=str.size();
                }
                else{//没到结束
                    v.push_back(str.substr(i,str.find(',',i)-i));
                    i=str.find(',',i);
                }
            }
        }
        cout<<((find(v.begin(),v.end(),name)!=v.end())?"Ignore":"Important!")<<endl;
    }
    return 0;
}


编辑于 2020-03-07 17:11:02 回复(5)
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNextLine()) {
			String s = sc.nextLine();
			String name = sc.nextLine();
			char[] ch = s.toCharArray();
			List<String> list = new ArrayList<>();
			int flag = 0;
			String res = "";
			for (int i = 0; i < ch.length; i ++ ) {
				if(flag == 0 && ch[i] == '"') {
					flag = 1;
					list.add(res);
					res = "";
				} else if(flag == 1 && ch[i] == '"') {
					flag = 0;
					list.add(res);
					res = "";
				} else if(flag == 1) {
					res += ch[i];
				} else if(flag == 0 && ch[i] != ',') {
					res += ch[i];
				}
			}
			list.add(res);
			boolean isFinded = false;
			for (String string:list) {
				if(name.equals(string)) {
					isFinded = true;
					break;
				}
			}
			if(isFinded) System.out.println("Ignore");
			else System.out.println("Important!");
		}
	}
}

发表于 2016-10-13 23:28:50 回复(1)
#include <iostream>
#include <string>
using namespace std;

bool isImportant(string& list, string& name) {
	char delim = ',';          // 默认以‘,’作为姓名的分隔符
	for (int i = 0; i < list.size(); i++) {
		if (list[i] == '"') {
			delim = '"';        
			continue;   
		}
		string people;
		while (list[i] != delim) {
			people += list[i++];
		}
		if (people == name) return false;
		delim = ',';
	}
	return true;
}

int main() {
	string list, name;
	while (getline(cin, list)) {
		getline(cin, name);
		list += ',';
		if (isImportant(list, name)) cout << "Important!" << endl;
		else cout << "Ignore" << endl;
	}
}

发表于 2023-08-28 14:34:23 回复(0)
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        
        while (in.hasNextLine()) {
            char[] chars = in.nextLine().toCharArray();
            
            Set<String> set = new HashSet<>();
            StringBuilder curName = new StringBuilder();
            boolean flag = false;
            for (int i = 0; i < chars.length; ++i) {
                char ch = chars[i];
                
                if (ch == '\"') {
                    flag = !flag;
                    continue;
                }
                
                if (ch == ',' && !flag) {
                    set.add(curName.toString());
                    curName.setLength(0);
                    continue;
                }
                
                curName.append(ch);
            }
            set.add(curName.toString());
            
            String name = in.nextLine();
            System.out.println(!set.contains(name) ? "Important!" : "Ignore");
        }
        
        in.close();
    }
}

发表于 2021-05-28 19:33:02 回复(0)
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            String s = in.nextLine();
            String str = in.nextLine();
            func(s,str);

        }
    }

    private static void func(String s, String str) {
        int count =2;//用来判断该名字是否在 " "之间的
        int left = 0;//记录左边 " 下标
        int right =0;//记录右边 " 下标
        boolean fig =true;//判断 ,
        for (int i = 0; i < s.length(); i++) {//遍历字符串s
            if(s.charAt(i) == '\"' && count ==2){//出现第一个左边 "
                left =i+1;
                count --;
                continue;
            }
            if(count ==2 && fig ==true){ //没有出现 " ,直接判断 s 与 str是否相等
                for (int j = 0; j < str.length(); j++) {
                    if(s.charAt(i+j) != str.charAt(j)){
                        fig =false;
                        break;
                    }
                }
                if(fig == true ){//相等
                    if(i+str.length()-1 == s.length()-1){//判断是否为最后一个名字
                        System.out.println("Ignore");
                        return;
                    }
                    if(s.charAt(i+str.length()) ==','){//走到这,不是最后一个名字 ,判断他下一个是否为 , 若是 , 直接结束
                        System.out.println("Ignore");
                        return;
                    }

                }
            }
            if(count ==2 && s.charAt(i) ==',' && fig ==false){ //没有出现 " 并却出现 , 让fig为true,执行下一次,下一次为名字的开头
                fig =true;
                continue;
            }
            if(s.charAt(i) == '\"' && count ==1){//出现 " 并且 count 为 1,此时找到了 " "  之间的名字
                right =i;
                count --;
            }
            if(count ==0){// 判断 " " 之间的名字是否与 str 相等
                if(str.equals(s.substring(left,right))){
                    System.out.println("Ignore");
                    return;
                }else{//不相等 count 重置 ,让 i为right 下一次 直接从 right+1 开始判断
                    count =2;
                    i=right;
                }
            }
        }
        System.out.println("Important!");//走到这,说明没有与之匹配的名字
    }
}


发表于 2023-05-06 19:43:41 回复(0)
import java.util.Scanner;
//链接:https://www.nowcoder.com/questionTerminal/286af664b17243deb745f69138f8a800
//        来源:牛客网
//        NowCoder每天要处理许多邮件,但他并不是在收件人列表中,有时候只是被抄送。
//        他认为这些抄送的邮件重要性比自己在收件人列表里的邮件低,因此他要过滤掉这些次要的邮件,优先处理重要的邮件。
//        现在给你一串抄送列表,请你判断目标用户是否在抄送列表中。
//输入
// Joe,Kewell,Leon
//Joe
//"Letendre, Bruce",Joe,"Quan, William"
//William
//输出:
//Ignore
//Important
public class Main {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNext()){
            String list= scanner.nextLine();
            String name= scanner.nextLine();
            StringBuffer stringBuffer=new StringBuffer();
            int flag=0;
            int k=0;
            int n=list.length();
            for (int i = 0; i <list.length(); i++) {
                if(list.charAt(i)=='"'){  //如果有双引号  则只要不是"就插入 一直找到另一个" 这一对的内容和name进行比较
                    for (int j = i+1; j <list.length() ; j++) {  //i+1是因为i当前为引号+1 从下一个字符开始录入
                        if(list.charAt(j)!='"'){   //则只要不是"就插入
                            stringBuffer.append(list.charAt(j));
                        }
                        if(list.charAt(j)=='"'){  //如果找到另一个"号了 就比较stringBuffer和name的内容 必须完全一致 就输出Ignore
                            k=j+1;  //如果找到另一个"号了 就说明这个字符串已经遍历完了  下次从这个" 的下一位开始找
                            if(stringBuffer.toString().equals(name)){
                                flag=1; //如果找到完全相同的就标记一下
                                System.out.println("Ignore");
                            }
                            stringBuffer.delete(0,stringBuffer.length()); //比较完一次就清空一次stringBuffer
                            break; //找到一对"" 就直接结束
                        }
                    }

                }
                if(k!=0&&(k-1)!=list.length()-1){  //判断之前是否有带""的字符串 如果不为就说明之前遍历了""字符串 那么下次就从k的位置往下找
                    i=k;                            //赋值之后变为0 便于下一次的""查找  并且判断当前的k不是我的字符串的末尾
                    k=0;
                }
                if(list.charAt(i)==','){ //使用,分割 如果找到,就说明之前的字符串为一个 对比stringBuffer和name 如果相同输出Ignore
                    if(stringBuffer.toString().equals(name)){
                        flag=1;
                        System.out.println("Ignore");
                    }
                    stringBuffer.delete(0,stringBuffer.length());  //比较完清空stringBuffer
                    continue;  //结束本次循环 跳过当前找到的,
                }
                if(i==list.length()-1){  //因为末尾是没有,结束的 所以判断当前的i是不是末尾 如果是就直接比较
                    stringBuffer.append(list.charAt(i));
                    if(stringBuffer.toString().equals(name)){  //比较文件末尾的stringBuffer和name 相同输出Ignore
                        flag=1;
                        System.out.println("Ignore");
                    }
                }
                stringBuffer.append(list.charAt(i));  //加入stringBuffer
            }
            if(flag==0){  //如果前面没输出Ignore  则代表没有找到收件人姓名 输出Important!
                System.out.println("Important!");
            }

        }
    }
}

发表于 2023-05-06 12:18:33 回复(0)
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            String name = scan.nextLine();
            int pos = 0;
            Set<String> s = new HashSet<>();
            while(pos < name.length()){
                if(name.charAt(pos) == '\"'){
                    int end = name.indexOf('\"',pos+1); //从pos+1位置往后查找第一个"
                    String tmp = name.substring(pos+1,end); //截取[pos,end)之间的字符串
                    s.add(tmp);
                    pos = end + 2;  //到下一个名字的开头首字符
                }else{
                    int end = name.indexOf(',',pos+1);
                    //已经查到了最后一个名字,不是以,结尾
                    if(end == -1){
                        end = name.length()-1;
                        s.add(name.substring(pos,end+1));
                        break;
                    }
                    String tmp = name.substring(pos,end);
                    s.add(tmp);
                    pos = end + 1;
                }
            }
            name = scan.nextLine();
            if(s.contains(name) == true){
                System.out.println("Ignore");
            }else{
                System.out.println("Important!");
            }
        }
    }
}

发表于 2023-02-18 15:48:11 回复(0)
// write your code here

import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        while (sc.hasNext()) {
            String s = sc.nextLine();
            String tar = sc.nextLine();
        
            //使用Set存储所有的抄送列表
            HashSet<String> set = new HashSet<>();
            int i = 0;
            int n = s.length();
            while (i < n) {
                if ('\"' == s.charAt(i)) {
                    //如果第一个字符是",找到后一个"。将之间的内容加入到Set
                    int end = s.indexOf("\"", i + 1);
                    set.add(s.substring(i + 1, end));
                    //更新i
                    i = end + 2;
                } else {
                    //不是",说明是单独的收件人,我们找下一个,
                    int end = s.indexOf(",", i + 1);
                
                    //如果没找到说明是最后一个收件人
                    if (end == -1) {
                        set.add(s.substring(i, n));
                        break;
                    }
                    set.add(s.substring(i, end));
                    i = end + 1;
                }
            }
            //判断set是否含有
            if (set.contains(tar)) {
                System.out.println("Ignore");
            } else {
                System.out.println("Important!");
            }
        }
    }
}

发表于 2022-10-01 16:57:15 回复(0)
判断字符串三种情况:
1. 已“xxx”开头 
2. 已 ' , ' 开头 
3. 已 xxx 开头
import java.util.Scanner;
import java.util.ArrayList;

public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()) {
            String str = in.nextLine();
            String cur = in.nextLine();

            ArrayList list = new ArrayList();
            for (int i = 0; i < str.length(); i++) {
                String ret = "";
                char c = str.charAt(i);
                
                // 1. 判断是"xxx"的情况
                if (c == '"') {
                    i++;
                    while (i < str.length() && str.charAt(i) != '"') {
                        ret += str.charAt(i);
                        i++;
                    }
                } else if (c == ',') {
                    // 2. 判断是','打头的情况(可分两种)
                    i++;
                    if(str.charAt(i) == '"'){
                        // 2.1 ','号后面是"xxx"的情况
                        i++;
                        while (i < str.length() && str.charAt(i) != '"') {
                            ret += str.charAt(i);
                            i++;
                        }
                    }else {
                        // 2.2 ','后面是xxx的情况
                        while (i < str.length() && str.charAt(i) != ',') {
                            ret += str.charAt(i);
                            i++;
                        }
                    }
                } else {
                    // 3. 已xxx开头的情况
                    while (i < str.length() && str.charAt(i) != ',') {
                        ret += str.charAt(i);
                        i++;
                    }
                }
                list.add(ret);
            }
            
            if (list.contains(cur)) {
                System.out.println("Ignore");
            } else {
                System.out.println("Important!");
            }
        }
    }
}


发表于 2022-06-03 10:02:28 回复(0)
// write your code here
import java.util.Scanner;
import java.util.WeakHashMap;

public class Main {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNext()){
            String s1=scanner.nextLine();
            String s2=scanner.nextLine();
            if (s1.contains("\"")){
                StringBuilder sb=new StringBuilder();
                int flg=0;
                for (int i = 0; i < s1.length(); i++) {
                    if (s1.charAt(i)=='\"'){
                        flg++;
                    }else if (flg%2==0 && s1.charAt(i)==','){
                        sb.append("#");//分割名字与名字的标志位
                    }else {
                        sb.append(s1.charAt(i));
                    }
                }
                s1=sb.toString();
                String[] nameList=s1.split("#");
                int i = 0;
                for (; i < nameList.length; i++) {
                    if (nameList[i].equals(s2)){
                        System.out.println("Ignore");
                        break;
                    }
                }
                if (i== nameList.length){
                    System.out.println("Important!");
                }
            }else {
                String[] nameList=s1.split(",");
                int i=0;
                for (;i< nameList.length;i++){
                    if (nameList[i].equals(s2)){
                        System.out.println("Ignore");
                        break;
                    }
                }
                if (i== nameList.length){
                    System.out.println("Important!");
                }
            }
        }
    }
}

发表于 2022-05-14 19:07:32 回复(0)
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String str = sc.nextLine();
            String target = sc.nextLine();
            char[] ch = str.toCharArray();
            int flg = 0;
            List<String> list = new ArrayList<>();
            String ret = "";
            for(int i = 0;i < ch.length;i++){
                if(flg == 0 && ch[i] == '"'){
                    flg = 1;
                    list.add(ret);
                    ret = "";
                }else if(flg == 1 && ch[i] == '"'){
                    flg = 0;
                    list.add(ret);
                    ret = "";
                } else if(flg == 1){
                    ret += ch[i];
                }else if(flg == 0 && ch[i] != ','){
                    ret += ch[i];
                }
            }
                list.add(ret);
            
            boolean temp = false;
            for(String ss : list){
                if(ss.equals(target)){
                    temp = true;
                    break;
                }
            }
            if(temp){
                System.out.println("Ignore");
            }else{
                System.out.println("Important!");
                
            }
        }
    }
}

编辑于 2022-05-19 17:21:18 回复(0)
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String s = sc.nextLine();
            String n = sc.nextLine();
            int ln = s.length();
            if(ln == 1){
                if(n.equals(s)){
                    System.out.println("Ignore");
                }else{
                    System.out.println("Important!");
                }
                continue;
            }
            int i = 0;
            out:while(i < ln){
                int j = i + 1;
                if(s.charAt(i) != '"'){
                    for(;j < ln;j++){
                        if(s.charAt(j) == ','){
                            if(n.equals(s.substring(i,j))){
                                System.out.println("Ignore");
                                break out;
                            }else{
                                i = j + 1;
                                break;
                            }
                        }
                    }
                }else{
                    i++;
                    for(;j < ln;j++){
                        if(s.charAt(j) == '"'){
                            if(n.equals(s.substring(i,j))){
                                System.out.println("Ignore");
                                break out;
                            }else{
                                i = j + 2;
                                break;
                            }
                        }
                    }
                }
                if(j == ln){
                    if(s.charAt(j-1) == '"'){
                        if(n.equals(s.substring(i,j-1))){
                            System.out.println("Ignore");
                        }else{
                            System.out.println("Important!");
                        }
                        break;
                    }
                    if(n.equals(s.substring(i,j))){
                            System.out.println("Ignore");
                        }else{
                            System.out.println("Important!");
                    }
                    break;
                }
            }
            if(i >= ln){
                System.out.println("Important!");
            }
        }
    }
}

发表于 2022-05-13 05:07:11 回复(0)
// write your code here cpp
#include <iostream>
#include <vector>
#include <set>
#include <string>
using namespace std;

int main(){
    string nameStr;
    string findStr;
    while(getline(cin,nameStr)&&getline(cin,findStr)){
        //思路:将namestr中的名字都划分开来,存入set中。
        set<string> table;
        int head = 0;
        int tail = 0;
        while(head < nameStr.size() && tail < nameStr.size()){
            //1.当名字以“开头时,tail去找“
            if(nameStr[head] == '\"'){
                ++tail;
                while(tail < nameStr.size() && nameStr[tail] != '\"'){
                    ++tail;
                }
                table.insert(string(nameStr.begin()+head+1,nameStr.begin()+tail));
                head = tail + 2;
                tail = head + 1;
            }
            //2.当名字不以“开头时,tail找,
            else{
                while(tail < nameStr.size() && nameStr[tail] != ','){
                    ++tail;
                }
                table.insert(string(nameStr.begin()+head,nameStr.begin()+tail));
                head = tail + 1;
                tail = head + 1;
            }
        }
        if(table.find(findStr)!=table.end()){
            cout<<"Ignore"<<endl;
        }
        else{
            cout<<"Important!"<<endl;
        }
    }
    return 0;
}

发表于 2022-04-04 11:47:59 回复(1)
// 将s1利用队列进行切分 然后存入到set中,之后在set中查找s2即可
#include<iostream>
#include<queue>
#include<string>
#include<set>

using namespace std;

string& getstring(queue<char>& q, string &s) 
{
    s.resize(0);
    while (!q.empty())
    {
        s += q.front();
        q.pop();
    }
    return s;
}
int main()
{
    string s1;
    string s2;
    while (getline(cin, s1))
    {
        getline(cin, s2);
        queue<char> q;
        bool sign = 0;
        string tmp = "";
        set<string> s;
        for (int i = 0; i < s1.size(); i++)
        {
            if (s1[i] == '"')
            {
               
                while (1 && i < s1.size())
                {
                    i++;
                    if (s1[i] != '"')
                    {
                        q.push(s1[i]);
                    }

                    if (s1[i] == '"')
                    {
                        break;
                    }
                }
                
                s.insert(getstring(q, tmp));
                i++;
                
            }
            else
            {
                
                if (s1[i] == ',')
                    i++;
                while (s1[i] != ',' && i < s1.size())
                {
                    q.push(s1[i]);
                    i++;
                }

               s.insert(getstring(q, tmp));

            }
        }
        if (s.count(s2))
            cout << "Ignore" << endl;
        else
        {
            cout << "Important!" << endl;
        }
        

    }
    return 0;
}

发表于 2022-04-01 14:06:26 回复(0)
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
    string str1, str2;
    while (getline(cin, str1))
    {
        getline(cin, str2);
        vector<string> v;
        int len1 = str1.size();
        int len2 = str2.size();
        for (int i = 0; i < len1; i++)
        {
            //有双引号是不用讨论单词是否为最后一个
            //因为双引号成对出现,一定能find到下标
            if (str1[i] == '\"' && i + 1 < len1)
            {
                i++;
                int idx = str1.find('\"', i);
                v.push_back(str1.substr(i, idx - i));
                i = idx + 1;
            }
            else
            {
                int idx = str1.find(',', i);
                //没有双引号要判断单词是否为最后一个
                //因为最后一个单词的末尾没有逗号
                //找不到会返回-1
                if (idx == string::npos)
                    v.push_back(str1.substr(i, len1 - i));
                else
                {
                    v.push_back(str1.substr(i, idx - i));
                    i = idx;
                }
            }
        }
        cout << ((find(v.begin(), v.end(), str2) != v.end()) ? "Ignore" : "Important!") << endl;
    }

    return 0;
}

发表于 2021-11-18 21:49:22 回复(0)
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	
	string str;
	string comp;
	while (getline(cin, str))
	{
		vector<string> vs;
		getline(cin, comp);
		int i = 0, j = 0;
		int flag = 0;
		string temp;
		for (int i = 0; i < str.size(); i++)
		{
			//flag = 1:在引号里面
			//flag = 0;在引号外面
			if (str[i] == '"'&& flag == 0)
			{
				flag = 1;
			}
			else if (str[i] == '"'&& flag == 1)
			{
				flag = 0;
			}
			else if (flag == 1)
			{
				temp.push_back(str[i]);
			}
			else if (flag == 0 && str[i] != ',')
			{
				temp.push_back(str[i]);
			}
			else if (flag == 0 && str[i] == ',')
			{
				vs.push_back(temp);
				temp.clear();
			}
			
		}
		vs.push_back(temp);
		temp.clear();
		flag = 0;
		for (auto e : vs)
		{
			if (e == comp)
				flag = 1;
		}
		if(flag == 1)
			cout << "Ignore" << endl;
		else
			cout << "Important!" << endl;
		flag = 0;
	}
}

发表于 2021-07-16 11:42:30 回复(0)
//直接分割列表,拿分割出的单词与name进行对比,
//相同就输出Ignore,不同就下一个单词,直到结束输出Important!,
// write your code here cpp
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str,name;
    while(getline(cin,str))
    {
        getline(cin,name);
        string temp;
        bool find=false;
        for(int i=0;i<str.size();i++)
        {
            if(str[i]=='\"')
            {
                temp=str.substr(i+1,str.find('\"',i+1)-i-1);
                i+=temp.size()+1+1;
            }
            else
            {
                temp=str.substr(i,str.find(',',i)-i-1);
                i+=temp.size()+1;
            }                
            if(temp==name)
            {
                 find=true;
                 cout<<"Ignore"<<endl;
                 break;
            }
            temp.clear();      
        }
        if(!find)
        {
             cout<<"Important!"<<endl;
        }
    }
}
发表于 2021-06-04 18:16:29 回复(0)

问题信息

难度:
26条回答 9956浏览

热门推荐

通过挑战的用户

查看代码