首页 > 其他分享 >#10049. 「一本通 2.3 例 1」Phone List

#10049. 「一本通 2.3 例 1」Phone List

时间:2022-12-01 22:35:24浏览次数:113  
标签:10049 ch val int List num fg 2.3 include

字典树板子题

#include<iostream>
#include <algorithm>
#include <cstring>
using namespace std;
 const int N=1e5+4;
 char num[40];
 int len,fg;
 int ch[N][15],tot,val[N];
 void insert(char *s){
     int i,u=1;
     
     for(i=0;i<len;i++){
         int c=s[i]-'0';
         if(ch[u][c]==0){
             ch[u][c]=++tot; 
         }
         else if(i==len-1) fg=0;
         u=ch[u][c];
         if(val[u]) fg=0;
     }
     val[u]=1;
 }
 
 main(){
     int i,cas; cin>>cas;
     while(cas--){
         fg=1; tot=1; 
         memset(ch,0,sizeof ch);
         memset(val,0,sizeof val);
         
      int tes; cin>>tes;
      for(i=1;i<=tes;i++){
          cin>>num,len=strlen(num); insert(num);
      }
      if(fg) cout<<"YES"; else cout<<"NO";
      cout<<endl;
    }
 }
 
 

 

标签:10049,ch,val,int,List,num,fg,2.3,include
From: https://www.cnblogs.com/towboa/p/16942996.html

相关文章

  • 61. Rotate List(易错)
    k places,where kForexample:Given ​​1->2->3->4->5->NULL​​ and k = ​​2​​,return ​​4->5->1->2->3->NULL​​.​​Subscribe​​ toseewhich......
  • 143. Reorder List(好)
    L: L0→L1→…→Ln-1→Ln,reorderitto: L0→Ln→L1→Ln-1→L2→Ln-2→…Youmustdothisin-placewithoutalteringthenodes'values.Forexample,Given ​​{......
  • 148. Sort List(重要)
    Sortalinkedlistin O(n log n)timeusingconstantspacecomplexity.用归并排序!相似的题目147.InsertionSortLi/***Definitionforsingly-linkedlist.*st......
  • List集合转换成数组
    我现在有个需求:将File集合转换成MultipartFile数组结构然后我就开始在网上开启了List转换到数组之旅。首先来看一个例子ArrayList<String>list=newArrayList<......
  • iOS学习之 plist文件的读写
    在做iOS开发时,经常用到到plist文件, 那plist文件是什么呢?它全名是:PropertyList,属性列表文件,它是一种用来存储串行化后的对象的文件。属性列表文件的扩展名为.plist ,因此......
  • Intelij idea 2022.2.3安装过程总结
    参考教程:https://www.exception.site/essay/idea-reset-eval详细安装过程参考了以上教程,本文对博主自己安装时遇到的问题进行总结。1.安装过程概述安装过程参考教程,一直......
  • list定义与方法使用
    #一、list列表#语法:[元素,元素,...]#1.定义一个listmy_list=['杰伦','学友','德华']print(my_list)print(type(my_list))#2.定义一个嵌套listmy_list=[[1,2,3],[4......
  • delphi 让TActionList中的sender指向事发对象
    故事这样的:我有一批按钮需要共同一个点击事件,本来是按最普通的方法,批选了这些按钮,然后双击click事件,然后写代码,最主要的是这句:iTag:=TControl(Sender).Tag;......
  • list、dict和set的综合应用:排课系统(4)
    上回说到,我们成功的实现了排课算法并且生成了课表,这次我们就尝试在首页显示课表,并且实现调用排课的认证。显示课表显示课表非常的简单,在视图中返回的context字典中只有一......
  • list 和 dict 的复制
    我们都知道,Python中有两种可变的数据类型:list和dict。这两种数据类型对应的实例也有很多方法可以对自身进行修改,需要注意的是,这里调用修改相关的方法的时候不是返回修改......