sscanf詳解(二)

幾個常用例子例1:得到devicetype的值,首先原始字串中是否包含devicetype=,如果包含此串兒則使用如下方式獲得devicetype的值。int main(int argc, char argv[]){string szMsg("_Community=public&_MachineName=192.168.6.96&_Port=161&devicetype=_SnmpWin&seid=2");char *pPos =

UVa 11218 – KTV

題意:讓你從n種搭配中,選出3個,使得選出的9個數字巧好是“1~9”不重複,在所有合格情況中輸出分數最高的情況。解法:dfs回溯,即:枚舉出所有合格情況從中選出分數最高的那個。代碼如下:#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using

UVa 10624 – Super Number

按題目要求,求出滿足能整除相應n~m之間所有數的最小的整數X。利用分步取餘法取餘+dfs,dfs時注意利用一些技巧減少取餘算數的次數,否則會逾時。代碼如下:#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;int n,

HDU 1518 – Square

使得給出的若干木棍可以拼出正方形,搜尋回溯,注意剪枝。代碼如下:#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>using namespace std;int num, lenth;int a[21], cct;bool vis[21], flag;int cmp(const void *x, const void

UVa 10115 – Automatic Editing

大體題意就是將列表第一列的字串不斷換成第二列的字串,直到將所給的整個句子中所有出現的第一列字串全部換掉為止,然後再進行下一個字串的替換。題目本身不難,相信只要認真一點,就可以輕鬆AC掉 ~(如果用上strstr()函數和sprintf函數會使代碼簡潔不少,效率也會提高不少。當然如果會用STL的string的話,同樣會很快。)代碼如下:#include<stdio.h>#include<string.h>#include<math.h>int

UVa 10391 – Compound Words

好久沒有1Y了 ~~~hash來做,先將所有字串存入雜湊表,然後將每一個字串分成兩個子串,分成的兩個子串能在雜湊表中找到,則其為“compound words”,將其輸出。代碼如下:#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using

UVa 10194 – Football

就是一個類比題,稍有麻煩,基本還算是簡單,但需注意的是題目有點問題,在第6條按字典序排序的時候是不分大小寫,在這裡被坑了兩次 ~~~代碼如下:#include<stdio.h>#include<string.h>#include<stdlib.h>#include<ctype.h>char tourname[1000+2],game[1000][100];typedef struct Team{ int b,c,d,e,f,g,h,i;

UVa 10125 – Sumsets

方法一:可以暴力枚舉,其實用枚舉方法水過純屬意外。(可以試一下1000個1這組資料,它是跑不出來的。)方法二:可以將問題轉化為 a+b=d-c。這樣,只要將a+b的值全部算出來,存至雜湊表內,再枚舉d,c的值看兩邊是否相等從而推出d,就可以將複雜度由O(n4)降之O(n2)左右的水準,便可以過了。代碼如下:方法一(枚舉 1.600s):#define test#include <iostream>#include <algorithm>#include

UVa 10887 – Concatenation of Languages

將A集合的詞與B集合中的詞按要求合成一個詞,然後利用雜湊表判重。代碼如下:#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;const int MAXSIZE = 2250002;int num,

UVa 11624 – Fire!

bfs,稍複雜的bfs,將火和人的位置分別bfs(先火再人),直到人到達邊界或是被火圍住無路可走時結束。代碼如下:#include <cstdio>#include <cstring>const int MAXN = 1001;struct point{ int x, y, mem_step; bool bool_fire;// 區分是否是‘火’} que[MAXN*MAXN];int r, c, fx, fy;int step_x[4]= {1,-1,0,0

UVa 10422 – Knights in FEN

剛開始審錯題以為是“上下左右”四個方向走,結果編出來以後,範例都沒跑過,又仔細審了審題,才明白過來,騎士的走法與國際象棋騎士的走法一樣,按'日'字走。方法比較簡單,因為資料量比較小,DFS回溯+雜湊判重足矣。代碼如下:#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath&

UVa 10085 – The most distant state

八數位問題的變形,bfs+雜湊,列印路徑時花了點時間,用雜湊表next數組的原理進行回退就可以將問題解決。代碼如下:#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;const int MAXSIZE = 1000003;

HDU 3699 A hard Aoshu Problem

A hard Aoshu ProblemTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 62768/32768 K (Java/Others)Total Submission(s): 345    Accepted Submission(s): 173Problem DescriptionMath Olympiad is called “Aoshu” in China. Aoshu is very popular in

HDU 1218 – Blurred Vision

簡單類比,題意有點難懂,實際就是給你一個 r*c 的矩陣,讓你轉化為一個(r-1)*(c-1)的矩陣,新矩陣中每個點的值為以其左上方為起點的四節點小矩陣之和的平均值。代碼如下:#include <cstdio>#include <cstring>int main(){ int r, c; char image[10][10], str[10]; while(scanf("%s", str) && strcmp(str,

UVa 10033 – Interpreter

類比題,關鍵是題意不太好理解,尤其是8,9兩條命令不太好理解。8da: 表示將地址為“寄存器a的值”的記憶體單元的值拷貝到寄存器d.9sa:表示將寄存器s的值拷貝到地址為“寄存器d的值”的記憶體單元.代碼如下:#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>using namespace std;int reg[10];

UVa 101 – The Blocks Problem

類比棧,這個題並不難,注意a、b積木相同時情況的處理就可以,但至今都不明白當時為什麼RE了那麼多遍,數組cn開小了就RE,但按題目說最多開個cn[25][25]的數組就足夠了,但我開到100多還是RE,結果一下開到200多就AC了,至今不知道是為什麼,求大神解釋啊~~~#include<iostream>#include<cstdio>#include<cstring>using namespace std;struct blocks{ int m,n;

UVa 10196 – Check The Check

類比題,代碼稍長,一定仔細。代碼如下:#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>using namespace std;char Map[8][9];int Hstep_x[8] = {2, 2, -2, -2, 1, 1, -1, -1};int Hstep_y[8] = {1, -1, 1, -1, 2, -2

10400 – Game Show Math

描述:根據前n個數看是否能夠湊出最後一個數,只能進行+、-、*、/四則運算,誰在前面,誰的優先順序高,不過會出現4^100,簡單的暴肯定會逾時的,稍微剪枝一下就可以過了#include <cstdio>#include <cstdlib>#include <cstring>char p[]= {'+','-','*','/'};int num[110];char str[110];int n,t,m;int hash[64010][110];bool dfs(

Uva 489: Hangman Judge

記得剛做UVa時,這個題卡了好幾次,後來用strchr函數做的才過的,不過後來用普通方法也實現了 。//方法一:#include<stdio.h>#include<string.h>int main(){ char a[1000],b[1000],c[27],d[27]; int i,k,num,count,number,flag,fgg; while(1) { scanf("%d",&k); memset(a,

HDU2821 Pusher HDU3500 Fling DFS搜尋

 PusherTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others)Total Submission(s): 169 Accepted Submission(s): 67Special JudgeProblem DescriptionPusherBoy is an online game http://www.hacker.org/push . There is an R * C grid,

總頁數: 61357 1 .... 13814 13815 13816 13817 13818 .... 61357 Go to: 前往

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.